Note that there are some explanatory texts on larger screens.

plurals
  1. POc#: what is the advantage to using the databinding control vs hard coding?
    text
    copied!<p>i am using the ms chart control to make funny looking charts on a winform. what is the advantage of using a databinding instead of say something like this:</p> <pre><code>using System.Windows.Forms.DataVisualization.Charting; using System.Data; using System.Data.OleDb; ... // Access database System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm)this.ParentForm; string fileNameString = mainForm.applicationPath + "\\data\\chartdata.mdb"; // Initialize a connection string string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString; // Define the database query string mySelectQuery="SELECT Name, Sales FROM REPS;"; // 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(); ... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload