Null Values

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

I have the following code in my code behind page for an apsx page...

If Not IsDBNull(DataSet1.tblMyTable(1).MyField) Then
'More Code
End if

It returns the following error - "Cannot get value because it is DBNull."

I can't even test for DBNull without an error.

How do I get around this?
 
You get the error because DataSet1.tblMyTable(1).MyField tries to cast the
object to type of MyField, but it fails, because MyField is DBNull.Value.
You use typed datasets, so you should use method call IsMyFieldNull() to
check can you use the MyField or not.

JMu
 
Thanks. Good Clear Explanation!

Jarmo Muukka said:
You get the error because DataSet1.tblMyTable(1).MyField tries to cast the
object to type of MyField, but it fails, because MyField is DBNull.Value.
You use typed datasets, so you should use method call IsMyFieldNull() to
check can you use the MyField or not.

JMu
 
Back
Top