Reputation: 3
I want to create chart that read the category column in my database.. I have repeating category because its general term and i notice this.
I have many "short" slice:
I dont have any idea how to merge the category with the same name and add its value..
Here's my code
MySqlCommand cmd = new MySqlCommand("Select * From sketchit.inventory;", dc.con);
MySqlDataReader myreader;
try {
dc.con.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read()) {
this.chart1.Series["Report 1"].Points.AddXY(myreader.GetString("Category"), myreader.GetInt32("Stocks"));
chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
}
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
dc.con.Close();
Upvotes: 0
Views: 82
Reputation: 37472
Use aggregation.
SELECT category,
sum(stocks) stocks
FROM sketchit.inventory
GROUP BY category;
Upvotes: 1