开发者

c# NotSupportedException was unhandled DATABINDTABLE

i am getting this exception on :

chart1.DataBindTable(myReader, "Name");

here;s the complete code:

// Access database
            //System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm)this.ParentForm;
            //string fileNameString = "\\data\\chartdata.mdb";

            // Initialize a connection string    
            string myConnectionString = "Provider=SQLOLEDB;Data Source=hermes;Initial Catalog=qcvaluestest;Integrated Security=SSPI;";

            // Define the database query    
            string mySelectQuery = "SELECT name, finalconc from qvalues where rowid in (20365,20366,20367);";

            // Create a database connection object using the connection string    
            OleDbConnection myConnection = new OleDbConnection开发者_C百科(myConnectionString);

            // Create a database command on the connection using query    
            OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

            // Open the connection    
            myCommand.Connection.Open();

            // Create a database reader    
            OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // Since the reader implements and IEnumerable, pass the reader directly into
            // the DataBindTable method with the name of the Column to be used as the XValue
            chart1.DataBindTable(myReader, "Name");

            // Close the reader and the connection
            myReader.Close();
            myConnection.Close();

what am i doing wrong? i know that it should be connecting. perhaps the sql statement isnt returning anything?


I'm not sure, but try to use myReader.Read() before DataBindTable or try this :

OleDbDataAdapter da = new OleDbDataAdapter(myCommand);                
DataTable data = new DataTable();
da.Fill(data);    
chart1.DataBindTable(data.AsDataView(), "name");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜