LimoMan المديـــــــــر العــــــــــــام
عدد الرسائل : 11484 نقاط : 9355 العمر : 42 العمل/الترفيه : مهندس برامج الدوله : Egypt رقم العضويه : [ 1 ] تاريخ التسجيل : 27/12/2007
| موضوع: How to send nullable datetime values to sqlserver الثلاثاء يناير 29, 2008 10:03 am | |
| Dear All,
I was having problems in sending null datetime values to sqlserver.
You may face the same problem when working with advanced search,
Where the user may choose to search by date or not.
After asking and searching a little, i found the solution
The Solution
We will use the type SqlDateTime.Null to pass null datetime value from visual studio to sqlserver
But, before that, we need to include the following class in the using section
using System.Data.SqlTypes;
Then, in your code, in case you want to send null datetime value, use the following code
SqlDateTime dtDateFrom; dtDateFrom = SqlDateTime.Null;
In case you are using stored procedure for your query, to check for the value sent from the visual studio, use the following code
@DateFrom AS datetime,
WHERE ( @DateFrom = null OR EVT_DateFrom >= @DateFrom )
It will return true if the value sent is null (SqlDateTime.Null) or the date in the table is larger than that sent to the stored procedure.
I tested it and it works fine for me .. :cheers:
In case you have any more inquiries about this issue, just put them.
HTH .. ;)
| |
|
اهلاوية طحن عضو جديد
عدد الرسائل : 17 نقاط : 0 العمر : 32 الدوله : قلوب الأهلاوية رقم العضويه : [ 185 ] تاريخ التسجيل : 09/12/2008
| موضوع: رد: How to send nullable datetime values to sqlserver الخميس ديسمبر 11, 2008 5:20 pm | |
| | |
|
LimoMan المديـــــــــر العــــــــــــام
عدد الرسائل : 11484 نقاط : 9355 العمر : 42 العمل/الترفيه : مهندس برامج الدوله : Egypt رقم العضويه : [ 1 ] تاريخ التسجيل : 27/12/2007
| |