Frage

How to query the rows based on DateTime in SQL Server 2005 Express installed on windows server 2008 r2?

I have code that selects rows based on from and to date values. It's working in my Windows 7 system . But, It's not working on Windows Server 2008 R2 ... Any help

this.filterreportTableAdapter.FillBy(this.cRdataset.filterreport_datatable, fromdate, todate);

and my SQL query is

SELECT * 
FROM tablename 
WHERE DATE BETWEEN @fromdate and @todate
War es hilfreich?

Lösung

It sounds like date/time values are being passed as strings. This is always a bad idea, and formatting issues abound. The best approach here is simply: use correctly-typed parameters. if both client and server know it is a DateTime, then it is passed as a primitive vaue, not a string - thus no formatting problems.

Make sure that fromdate and todate in the c# are DateTime, and that @fromdate, @todate and tablename.DATE in the TSQL are datetime.

Andere Tipps

Please set the datetime format same as the one on your windows 7 e.g. : dd/MM/yyyy

it seems that you have a date format mistake when passing date parameters. there are two solutions: first, you can try to use date format that works everywhere that is: YYYYMMDD ex : 20120722. another solution is to make a DateDiff in sql query Best regard

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top