Reputation: 113
I have the WHERE clause in my query that goes like
WHERE (FORMAT([salesdate], "yyyy") = @year;
Then I added the parameter @year like this:
myCommand.Parameters.Add(new OleDbParameter("@year", (year)));
It should filter records that has sales date according to a chosen year. But it returns nothing. I'm sure that my variable year got it right. I'm also sure that the Parameter.Add is on the right place.
I also tried the same query on MS Access, with input value for the parameter, then it worked.
What am I doing wrong?
Upvotes: 0
Views: 46
Reputation: 3705
Try this instead:
WHERE DATEPART(YEAR, [salesdate]) = @year;
There is a different way of adding parameters, you can try that in combination with DATEPART:
myCommand.Parameters.Add("@year", OleDbType.Integer).Value = year;
Upvotes: 1