2010-11-02 46 views
1

我得到这个异常:C#NotSupportedException异常是未处理DATABINDTABLE

chart1.DataBindTable(myReader, "Name"); 

这里; S的完整代码:

// 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(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(); 

我到底做错了什么?我知道它应该连接。也许sql语句不返回任何东西?

+1

,什么是chart1? – 2010-11-02 16:51:50

+0

它的MSChart。 。 。 – 2010-11-02 16:52:06

回答

2

我不知道,但尝试DataBindTable前使用myReader.Read()或试试这个:

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