I have an insertRecord function in vb.net that uses a parameter query. If there is no error date given, I need to insert dbnull.value into the db instead of ""(Nothing).
Dim strErrorDate2 As DateTime = Request.Form("dateOfErrorDatePicker2").ToString
.Add(New SqlParameter("@ErrorDate2", If(strErrorDate2 <> Nothing, strErrorDate2.Date, DBNull.Value)))
I keep getting conversion errors on dbnull to string. Originally it had it's own if/else block where I initialized the variable, but I couldn't figure out how to convert it correctly. I tried the inline if, but I still need to do a conversion or try something else.
Any ideas? The problem is that when I insert an empty string or DateTime into the database it records as a min possible date such as 1/1/1900.
EDIT: "Cannot infer a common type, 'object' assumed." That's the error I'm currently getting.
Nothing?Option Strict Onas the first line of the file with that code in. Then, when you have fixed the problems it highlights, your code may be in a working state :)