dpatfield66
Well-known member
- Joined
- Apr 6, 2006
- Messages
- 136
- Programming Experience
- 5-10
I've seen some postings on Null Values, but they don't seem to help me.
How can I pass a NULL value to an SQL Table Date Field, if I'm using a Masked Text Box to store the value in the forms?
In other words, if the text of this box is "", how can I get the Insert method to accept as an argument (DBNull)?
Remember, my paramater wants a DateValue. If the string that comes from the Masked Text Box is a valid date, then the parameter will work, but if it's "", the error is: "Cannot convert "" to Date" In this case I just want make the paramater NULL, but DBNull will not be accepted in the paramater. I cannot set any variables to NULL, except I believe the OBJECT type, and when I do that, I get a cast error on the paramater.
Ex:
dim objDate as Object
If Me.txtADate.Text = "" Then
objDate = System.DBNull
Else
objDate = Me.txtADate.Text
End If
But when I say obixAdmitTableAdapter.Insert(objDate), I get the cast error. Because the argument wants a date value.
There is some behind-the-scenes code that I've updated for the Insert Method but everytime I come back at a later date, the code has disappeared and the original code is there. I tried saving and then closing the app, and then re-opening, and the code is there, but just today, for some reason it's wiped out again. Not sure what I do that erases it.
How can I pass a NULL value to an SQL Table Date Field, if I'm using a Masked Text Box to store the value in the forms?
In other words, if the text of this box is "", how can I get the Insert method to accept as an argument (DBNull)?
Remember, my paramater wants a DateValue. If the string that comes from the Masked Text Box is a valid date, then the parameter will work, but if it's "", the error is: "Cannot convert "" to Date" In this case I just want make the paramater NULL, but DBNull will not be accepted in the paramater. I cannot set any variables to NULL, except I believe the OBJECT type, and when I do that, I get a cast error on the paramater.
Ex:
dim objDate as Object
If Me.txtADate.Text = "" Then
objDate = System.DBNull
Else
objDate = Me.txtADate.Text
End If
But when I say obixAdmitTableAdapter.Insert(objDate), I get the cast error. Because the argument wants a date value.
There is some behind-the-scenes code that I've updated for the Insert Method but everytime I come back at a later date, the code has disappeared and the original code is there. I tried saving and then closing the app, and then re-opening, and the code is there, but just today, for some reason it's wiped out again. Not sure what I do that erases it.