how to test for System.DBNull

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

'Next line is suto code. it doesnt compile
If sender.Value Is System.DBNull.Value Then
ID = 0
Else
ID = sender.Value
End If

Chris
 
How can I test to see if an object is System.DBNull? I have an event and
need to get the value from a parameter like this:


Private Sub ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Try
Dim ID As Int32
'Next line is suto code. it doesnt compile
If sender.Value Is System.DBNull Then
ID = 0
Else
ID = sender.Value
End If


If I put a watch on "sender.Value" its value is {System.DBNull}.

Thanks.
 
Moondaddy,

Value is not a member of object

However the sender is the object that is sending this object and because
that every object derives from object, can you forever (direct)cast it.

Therefore it probably has to be something as
\\\\
DirectCast(sender, YourSendingObjectType).value Is Dbnull.value.
////

I hope this helps,

Cor
 
THANKS! That did it!

--
(e-mail address removed)
Chris said:
'Next line is suto code. it doesnt compile
If sender.Value Is System.DBNull.Value Then
ID = 0
Else
ID = sender.Value
End If

Chris
 
moondaddy said:
How can I test to see if an object is System.DBNull? I have an event and
need to get the value from a parameter like this:

Private Sub ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Try
Dim ID As Int32
'Next line is suto code. it doesnt compile
If sender.Value Is System.DBNull Then

\\\
If sender.Value Is DBNull.Value Then
...
End If
///
 

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

Back
Top