-
Nov 22nd, 2010, 02:03 AM
#1
Thread Starter
Lively Member
how to insert null value in date field?
i have a maskedtextbox which will accept only date in the format of "DD-MM-yyyy" no i want to insert this date in my db. i have done this successfully.
Now i want to insert null value in through that maskedtextbox .
please give me a sample code for the above
-
Nov 22nd, 2010, 02:21 AM
#2
Re: how to insert null value in date field?
Check if the textbox is blank then insert System.Data.SqlTypes.SqlDateTime.Null to DB date field.
-
Nov 22nd, 2010, 02:32 AM
#3
Thread Starter
Lively Member
Re: how to insert null value in date field?
thanks for ur reply. i am using odbc connection so i need odbc connectivity code
-
Nov 22nd, 2010, 03:23 AM
#4
Re: how to insert null value in date field?
I would suggest not using a MaskedTextBox. The .NET Framework provides the DateTimePicker for date/time display and input. If you want to support null values, set ShowCheckBox to True and use whether or not it is checked to determine whether to insert a value or not, e.g.
vb.net Code:
If completedDatePicker.Checked Then row("CompletedDate") = completedDatePicker.Value.Date Else row("CompletedDate") = DBNull.Value End If
You always use DBNull.Value to represent a null value no matter the data type or the provider.
-
Nov 22nd, 2010, 04:44 AM
#5
Re: how to insert null value in date field?
Simply inserting NULL will do the job , I guess.
-
Nov 22nd, 2010, 04:49 AM
#6
Re: how to insert null value in date field?
Originally Posted by amrita
Simply inserting NULL will do the job , I guess.
Only if you write it literally into the SQl code, which you shouldn't do. If you're using parameters, as you should, or a DataTable then you must use DBNull.Value.
-
Nov 22nd, 2010, 06:07 AM
#7
Banned
Re: how to insert null value in date field?
thank u so much for sharing this
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|