Wednesday 23 April 2014

How to link chart Graph with database in window form


                                                                                                                                       Previous
                                                                                                                                           Next

Here i will explain that how to connect Chart-Graph with database.

Step(1): Form
Drag and down a chart graph and a button from tool box.

Step(2): Coding
Now click on Button (Load Button). and write this code


private void Load_button_Click(object sender, EventArgs e)
    SqlConnection con = new SqlConnection("server = MUNESH;Database=datastore;UID=sa;Password=123;");
    SqlCommand cmd = new SqlCommand("Select * from data1", con);
DataReader mydatareader ;
 try
   {
con.Open();
myreader = cmd.ExecuteReader();
while(myreader.Read())
{
this.chart1.Series["Age"].Points.AddXY(myreader.GetString("name"),myreader.GetInt32("Age"));
}
}
Catch(Exception ex)
{
MessageBox.show(ex.message);
}
}
Step(3) : Run
Now run your application and click on button.
                                                                                                                                       Previous
                                                                                                                                           Next

No comments:

Post a Comment

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...