How can I pass a null value for date in vb.net to sql stored procedure?
54,929
Just assign the parameter the value DBNull.Value
[EDIT]
If you are using SqlParameter (thanks Jon) then you can set it like this if it gives any error
parameter.Value = DBNull.Value
Author by
Nandini
Updated on May 03, 2020Comments
-
Nandini about 4 years
My application is asp.net with vb.
In my page I have a textbox for passing date. If I didn't enter date and on clicking submit, I have to pass null value to the stored procedure.
I tried following codes such as
DBNull.Value
andDateTime.MinValue
. In that case instead of null,"#12:00:00#"
is passing. I have to pass Null. -
Nandini over 15 yearsit gives a conversion problem.can it be solved by Convert.ToDateTime(DBNull.Value)
-
Nandini over 15 yearsDBNull.Value cannot be used as it generates an error "Object cannot be cast from DBNull.Value to other types"
-
Jon Skeet over 15 yearsThe code given should be fine, if "parameter" is a SqlParameter.
-
AllisonC about 7 yearsShouldn't this line be
pflt_dateto.SqlValue = DBNull.Value
? I got the error: "DBNull is a type and cannot be used as an expression" without.Value