Click to See Complete Forum and Search --> : comparing datetime values


cgtalk
July 27th, 2008, 02:33 PM
hi
is there any good way that i can use to compare:
a datetime value stored in sql server 2005 table and datetime value that has been created in c#

format of datetime in sql server 2005: 4/22/2008 12:00:00 AM
format of datetime in c#: 4/22/2008 12:00:00 AM

in other words, is this query legal becouse i got an internal error when it's beign executed



"select A, B, C from TABLE1 where d=(select c from table2 where r='" + v1 + "' and rr='" + v2 + "') and Date>="+fromdate+" and Date<="+todate+"";

Arjay
July 27th, 2008, 02:44 PM
Does the query work in SQL Management studio when run from a query window (with the dates replaced with variables of course)?

cgtalk
July 27th, 2008, 03:04 PM
i worked now
i missed these qutations
Date>=' "+fromdate+" ' and Date<=' "+todate+" ' "

thanks anyway

darwen
July 27th, 2008, 03:18 PM
You should be using parameterised queries ('http://aspnet101.com/aspnet101/tutorials.aspx?id=1') to get around this (and many, many more) issues.

Darwen.