Unnecessary Changes in Chart(Image Link) I am working on C#,Winform.This is My Code.I am trying show by chart the number of people registered in selected date Which is working perfectly at first selection of date from dateTimePicker, But at the second selection and second time button click it showing unexpected changes(Please refer the image for perfect understanding). So I don't want this changes I want every time it user pick date he has to get perfect output of only 5 bars.How I can do that? Please Help!Thanks In Advance.
private void LoadChart_Click(object sender, EventArgs e)
string date1 = dateTimePicker1.Value.ToString("dd-MM-yyyy");
string date2 = dateTimePicker1.Value.AddDays(1).ToString("dd-MM-yyyy");
string date3 = dateTimePicker1.Value.AddDays(2).ToString("dd-MM-yyyy");
string date4 = dateTimePicker1.Value.AddDays(3).ToString("dd-MM-yyyy");
string date5 = dateTimePicker1.Value.AddDays(4).ToString("dd-MM-yyyy");
string cmdTextDate = "SELECT * FROM AllInOneTable WHERE Date=@Date";
OleDbCommand commandDate = new OleDbCommand(cmdTextDate, my_con);
commandDate.CommandText = cmdTextDate;
DataSet data = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(commandDate);
int a = data.Tables.Rows.Count;
string cmdTextDate2 = "SELECT * FROM AllInOneTable WHERE Date=@Date";
OleDbCommand commandDate2 = new OleDbCommand(cmdTextDate2, my_con);
commandDate2.CommandText = cmdTextDate2;
DataSet data2 = new DataSet();
OleDbDataAdapter da2 = new OleDbDataAdapter(commandDate2);
int b = data2.Tables.Rows.Count;
string cmdTextDate3 = "SELECT * FROM AllInOneTable W
Try clearing the series (below) then re-add the new data afterwards. Not sure if that's 100% what you want, but seems like it.
//for your code
Also on a side note - You rarely should call SELECT * FROM or do multiple calls to the database to retrieve information that can be done with a single query.
If you're using sql, look into GROUP BY and UNION keywords for sql queries. It'll allow you to condense multiple calls into one. Then separate it as you see fit, if you see the need. Linq will come in handy here.
This Example will show you an overview of what I'm talking about even if it's not contextually the same. It is a little more advanced however.
Asked in February 2016Viewed 1,669 timesVoted 11Answered 1 times