By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

Save Null Value to SQL Table in DateTime Field??

P: n/a
I have a text box that records a date. If the user enters a date in
the text box, and click on save, the date will be saved in the SQL
table, but if the user does not enter a date in this field and then
clicks save, I reveive the following message:
Cast from string "" to type 'Date' is not valid

The DateTime field in my table has Allow Nulls set to true. How can I
prevent this error from occuring if the user decides not to enter in a
date into the textbox when saving arecord?

Thanks,
C.R.
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You have to set the value to DBNull.Value instead of '

Tu-Thac

----- crjunk wrote: ----

I have a text box that records a date. If the user enters a date i
the text box, and click on save, the date will be saved in the SQ
table, but if the user does not enter a date in this field and the
clicks save, I reveive the following message
Cast from string "" to type 'Date' is not vali

The DateTime field in my table has Allow Nulls set to true. How can
prevent this error from occuring if the user decides not to enter in
date into the textbox when saving arecord

Thanks
C.R

Nov 18 '05 #2

P: n/a
"Tu-Thach" <tu*****@ongtech.com> wrote in message news:<28**********************************@microso ft.com>...
You have to set the value to DBNull.Value instead of ''

Tu-Thach


I tried using the following code when saving a record but I received
this error message: "Cast from string "" to type 'Date' is not valid"

If eProposalReceived.Text.Trim = "" Then
Row.Item("ProposalReceived") = DBNull.Value
End If

Am I doing something wrong?

Thanks,
C.R.
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.