Can someone tell me why this code produces error?
The C# code
DateTime now = DateTime.Now;
DateTime after1month = DateTime.Now.AddMonths(1);
The query it produce
SELECT * FROM TABLE WHERE THEDATE BETWEEN 'now' AND 'after1month'
Any help is appreciated.
Thx
This should look more like this:
Sometimes you can do it directly on SQL Server side using query:
without parameters from .NET.
Added (after comment):
dateaddis a SQL Server function that allows to add a specyfic interval to date and returns it.In this case
dateadd(mm, 1, getdate())adds one (1) month (mm) to current datetime (getdate()). More info on datepart identifiers and function itself on MSDN dateadd.