private DataTable GetData() { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbx"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("usp_Chart1", conn)) { cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
DataTable dtData = new DataTable(); dtData.Load(reader);
return dtData; } } } } }
Stored Procedure: usp_Chart1
CREATE PROCEDURE [dbo].[usp_Chart1] AS BEGIN SELECT SUM(Total) AS 'Total' ,DATEPART(yyyy, DateOfOrder) AS 'Year' FROM [dbo].[Orders] GROUP BY DATEPART(yyyy, DateOfOrder) HAVING DATEPART(yyyy, DateOfOrder) >= 1980 AND DATEPART(yyyy, DateOfOrder) <= 1985 END GO
Comments
Post a Comment