Null Values

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?
 
J

Jarmo Muukka

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
 
C

Craig

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
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top