Cast DBNULL problems

G

Guest

Hi! I have a problems with DBNULLs
I have a date field and couple of other fields, when I save my data, if it was a null when I got the data I want to keep that data intact even if it was a DBNULL
Little example
function savedata(DateFinish as date,Room as string...etc.

savedata(cdate(DatePicker.value,txtRoom.text
If the Date is DBNULL I will have an error Cast DBNULL to date type is invalid

I'm a new in the .NET world, Thanks Joel :)
 
S

Scott M.

If IsDBNull(value) then
handle the null value
Else
handle the data
End If


Joel said:
Hi! I have a problems with DBNULLs.
I have a date field and couple of other fields, when I save my data, if it
was a null when I got the data I want to keep that data intact even if it
was a DBNULL.
 
J

Joel

I know I can do that but I don't want to change the DBNULL value to
something. I want to send back a null value to the DB, if I originally
receive it like that.
A good exmaple is a Finish date, if the work is not finish the User will
receive the date as a null and that don't mean he will change it.

Thanks Joel :)
 
S

Shane Brodie

I think you might be looking for:

SqlDateTime.Null

"Represents a null value that can be assigned to the Value property of an
instance of the SqlDateTime structure."

Regards

Shane Brodie
 
S

Scott M.

My example will not change the data in the DB if it is null.

You can write the statement another way:

If Not IsDBNull(value) then
handle the data
End If

If there is a null value you won't do anything with it.
 
J

Joel

Thanks I will check this out. Joel :)
Shane Brodie said:
I think you might be looking for:

SqlDateTime.Null

"Represents a null value that can be assigned to the Value property of an
instance of the SqlDateTime structure."

Regards

Shane Brodie
 

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

Top