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.
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