private void Button1_Click(object sender, EventArgs e) { DataTable sd = new DataTable(); if (comboBox1.Text == "all") { con.Open(); SqlCommand command = new SqlCommand("select * from sreport3 where Time between'" + dateTimePicker1.Value.ToString() + "'and'" + dateTimePicker2.Value.ToString() + "'", con); SqlDataReader reader = command.ExecuteReader(); sd.Load(reader); dataGridView1.DataSource = sd; reader.Close(); con.Close(); } else { con.Open(); SqlCommand command = new SqlCommand("select * from sreport2 where Time between'" + dateTimePicker1.Value.ToString() + "'and'" + dateTimePicker2.Value.ToString() + "' INTERSECT select * from sreport2 where username = '" + comboBox1.Text.ToString() + "'", con); SqlDataReader reader = command.ExecuteReader(); sd.Load(reader); dataGridView1.DataSource = sd; reader.Close(); con.Close(); } chart1.Series["Live"].XValueMember = "Time"; chart1.Series["Live"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime; chart1.Series["Live"].YValueMembers = "CountOfusername"; chart1.Series["Live"].YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double; chart1.DataSource = sd; chart1.DataBind(); DataTable sd1 = new DataTable(); if (comboBox2.Text == "all") { SqlDataAdapter sdf1 = new SqlDataAdapter("select * from type2 where Time between'" + dateTimePicker1.Value.ToString() + "'and'" + dateTimePicker2.Value.ToString() + "'INTERSECT select * from type2 where username = '" + comboBox1.Text.ToString() + "'", con); sdf1.Fill(sd1); dataGridView2.DataSource = sd1; } else { SqlDataAdapter sdf1 = new SqlDataAdapter("select * from type2 where Time between'" + dateTimePicker1.Value.ToString() + "'and'" + dateTimePicker2.Value.ToString() + "'INTERSECT select * from type2 where type = '" + comboBox2.Text.ToString() + "'INTERSECT select * from type2 where username = '" + comboBox1.Text.ToString() + "'", con); sdf1.Fill(sd1); dataGridView2.DataSource = sd1; } chart2.Series["Type"].XValueMember = "Time"; chart2.Series["Type"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime; chart2.Series["Type"].YValueMembers = "CountOfusername"; chart2.Series["Type"].YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double; chart2.DataSource = sd1; chart2.DataBind(); }
Quote:dateTimePicker1 is full date i have one column in my table (time)
SELECT YEAR(Time) as SalesYear, MONTH(Time) as SalesMonth, SUM(Price) AS TotalSales FROM sreport3 GROUP BY YEAR(Time), MONTH(Time) ORDER BY YEAR(Time), MONTH(Time)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)