2010-11-02 4 views
1

Je reçois cette exception sur:C# NotSupportedException était non gérée DATABINDTABLE

chart1.DataBindTable(myReader, "Name"); 

ici; s le code complet:

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

ce que je fais mal? Je sais qu'il devrait être connecté. peut-être que la déclaration sql ne retourne rien?

+1

et ce qui est chart1? –

+0

son mschart. . . –

Répondre

2

Je ne sais pas, mais essayez d'utiliser myReader.Read() avant DataBindTable ou essayez ceci:

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