ASP.NET tag checked, so you may need to resolve problem in SQL query. I recommend you to use
stored procedure[
^], because it can also improves performance:
CREATE PROCEDURE GetDataByMonthAndYear
@iMonth INT,
@iYear INT
AS
BEGIN
DECLARE @bDate DATETIME
DECLARE @eData DATETIME
SET DATEFORMAT ymd;
SET @bDate = DATEADD(mm, @iMonth-1,DATEADD(yy, @iYear-1900, '1900-01-01'))
SET @eDate = DATEADD(dd, -1,DATEADD(mm, 1,@bDate))
SELECT Field1, Field2, Field3, FieldN
FROM YourTableName
WHERE [DateField] BETWEEN @bDate AND @eDate
END
On MS SQL Server 2012 you can use
DATEFROMPARTS[
^] function to build dates from parts.