Kishore Konatham

Kishore Konatham

  • NA
  • 63
  • 7.5k

How to add two tables data to the chart from the database?

Aug 22 2019 2:15 AM
I've tried this. Please let me know the alternative 
 
 
private void Form1_Load(object sender, EventArgs e)
{
string c = @"Data Source=mydts; Initial Catalog=SampleDB; Integrated Security=True";
SqlConnection conn = new SqlConnection(c);
conn.Open();
 
//Adding Income from Transactions table 
string query = "select Income from Transactions";
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
chart1.DataSource = ds;
chart1.Series["Income"].XValueMember = "Income";
chart1.Series["Income"].YValueMembers = "Income";
//Adding Expenses from Transactions1 table 
string query1 = "select Expenses from Transactions1";
SqlCommand cmd1 = new SqlCommand(query1, conn);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
chart1.DataSource = ds1;
chart1.Series["Expenses"].XValueMember = "Expenses";
chart1.Series["Expenses"].YValueMembers = "Expenses";
conn.Close();
}
 
 
Why can't it add two values from differet tables?
 
 
 
 
 
Thank you. 

Answers (1)