2
Answers

SQL Server Express 2005 and Date field

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)
1
Ankit Sharma
NA 8.8k 141k 7y
Hi Purvesh,
 
please refer to these links
 
https://www.codeproject.com/tips/846204/how-to-send-mail-using-sql-server-part
 
https://stackoverflow.com/questions/13300881/how-to-send-email-from-sql-server
 
you can write a SP to iterate through table using cursor, use this link
 
https://stackoverflow.com/a/20662486 
0
Rajeesh Menoth
NA 24.7k 629.6k 7y
Hi,
 
Try the microsoft docs code :
 
https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-send-dbmail-transact-sql 
 
Other Reference : 
 
https://www.emailarchitect.net/easendmail/kb/sql.aspx?cat=0
 
http://www.c-sharpcorner.com/UploadFile/ee01e6/how-to-send-mail-by-using-sql-server-part-2/