Save Null Value to SQL Table in DateTime Field??

C

crjunk

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.
 
G

Guest

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
 
C

crjunk

Tu-Thach said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top