views:

4859

answers:

1

Hi guys,

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 and DateTime.MinValue. In that case instead of null ,"#12:00:00#" is passing. I have to pass Null. So can anybody give me an appropriate solution for this?

+4  A: 

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
Binoj Antony
it gives a conversion problem.can it be solved by Convert.ToDateTime(DBNull.Value)
Nandini
DBNull.Value cannot be used as it generates an error "Object cannot be cast from DBNull.Value to other types"
Nandini
The code given should be fine, if "parameter" is a SqlParameter.
Jon Skeet