DataRow?

C

Charles A. Lackman

Hello,

I am working with DataRows and I am using the following:

DataRow = Dataset.Tables("MyTable").Rows(0)

If DataRow("ID") = Nothing Then
'Do Something
Else
'Do Something Else
End If

The problem is that even though there is a value for ID the If... Then
Statement is acting like there is Nothing.
I have checked the value and the DataRow does contain an ID. It is like
there is something wrong with the Runtime and Nothing is not being
interpreted correctly. I have simular instances of this in the same program
and they work like expected.

Any Suggestions would be greatly appreciated,

Chuck
 
M

Miha Markic

Hi Charles,

You should use Is instead of operator =.
If DataRow("ID") Is Nothing Then
....
Furthermore you should compare the value with DBNull.Value instead of
Nothing.
If DataRow("ID") Is DBNull.Value Then
 
C

Cor

Hi Miha,

There exist a Datarow("ID") Is Nothing situation,

That is with an XML dataset where some elements don't exist in a row, but I
think also that that is not in this situation.

Cor
 
M

Miha Markic

Interesting.
If you try to set row("Id") = nothing it will still hold DBNull.Value.
 

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