SQL Server Express 2005 and Date field

Feb 17 2009 10:07 AM
I am using SQL Server Express 2005 as my Database and programming in C# 2005. In one of my Table "Results" I have a field named "ResultDate" of DateTime data type. In my form I have a DateTimePicker. I want to save only one record for a particular date, hence while saving the record I am checking whether a record for that particular date is available.

My Query string is "Select * from Results where ResultDate = " + dtpresultDate.value;

But it is not working. SQL stores both Date and Time in a DateTime field, so it is saving 12:00:00 in addition to the given date while saving the record. DateTimePicker is including the current time to the value. I tried to use "dtpResultDate.Value.ToShortDateString", but it is giving me an error about data type mismatch. I also tried using convert, but the problem was in India we generally use "dd/mm/yy" as short date format, whereas the closest match is "dd/mm/yyyy". Do I have to use "dd/mm/yyyy" in my DateTimePicker also?


How should I modify the Query string so that a match is done only using the Date parts (ignoring the Times)?

Also can I use Count to check whether a record is available?

Thank you.

Lalit Kumar Barik
India

Answers (2)