Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a chart with query it work with me in daily count bout i want to make it count by month or year let me shoes
im not good in asking so i have 2 chart and 2 table and one search button wes this code

C#
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)


What I have tried:

i search about it muny time and i didn't find anything plz help
Posted
Updated 25-Dec-18 1:52am
v2

1 solution

Something like this should do the trick:
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)
 
Share this answer
 
v2
Comments
el_tot93 25-Dec-18 7:49am    
thx bout it didn't help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900