C# Code
using System;
using System.Data;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
namespace ChartDemoVC3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
FromComboBox.Text = "2012";
ToComboBox.Text = "2015";
LoadData();
}
private void LoadData()
{
SalesByYearChart.DataSource = GetData();
SalesByYearChart.Series["Series1"].Points.Clear();
SalesByYearChart.Series["Series1"].XValueMember = "Year";
SalesByYearChart.Series["Series1"].YValueMembers = "Total";
}
// DataSet, Objects, Array, Collection, Generics, DataTable
private DataTable GetData()
{
DataTable dtChartData = new DataTable();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbx"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_ChartData2", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
cmd.Parameters.AddWithValue("@FromYear", FromComboBox.Text);
cmd.Parameters.AddWithValue("@ToYear", ToComboBox.Text);
SqlDataReader reader = cmd.ExecuteReader();
dtChartData.Load(reader);
}
}
return dtChartData;
}
private void GoButton_Click(object sender, EventArgs e)
{
LoadData();
}
}
}
Stored Procedure: [dbo].[usp_ChartData2]
CREATE PROCEDURE [dbo].[usp_ChartData2]
(
@FromYear NVARCHAR(50)
,@ToYear NVARCHAR(50)
)
AS
BEGIN
SELECT SUM([Total]) AS 'Total'
,DATEPART(yyyy, [DateOfOrder]) AS 'Year'
FROM [dbo].[Orders]
GROUP BY DATEPART(yyyy, [DateOfOrder])
HAVING DATEPART(yyyy, [DateOfOrder]) >= @FromYear AND DATEPART(yyyy, [DateOfOrder]) <= @ToYear
END
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :