Help with DBNUll

G

Guest

Hello:

When I try to do the following,
Dim liTemp As System.DBNull
If c.Value Is Nothing Then
newDataTableRow(c.Column.Key) = liTemp
Else
newDataTableRow(c.Column.Key) = c.Value
End If
I get the exception:

Exception Details: System.ArgumentException: Cannot set Column 'D_STAT_DT'
to be null. Please use DBNull instead.

Am I not doing that?

Venki
 
B

Bart Mermuys

Hi,

vvenk said:
Hello:

When I try to do the following,
Dim liTemp As System.DBNull
If c.Value Is Nothing Then
newDataTableRow(c.Column.Key) = liTemp
Else
newDataTableRow(c.Column.Key) = c.Value
End If
I get the exception:

Try using DBNull.Value, eg:

If c.Value Is Nothing Then
newDataTableRow(c.Column.Key) = DBNull.Value
Else
newDataTableRow(c.Column.Key) = c.Value
End If

hth,
Greetings
 
H

Herfried K. Wagner [MVP]

vvenk said:
When I try to do the following,
Dim liTemp As System.DBNull
If c.Value Is Nothing Then
newDataTableRow(c.Column.Key) = liTemp

Replace the line above with '...(...) = DBNull.Value'. 'DBNull' is a type
and thus cannot be assigned to the variable.
 
C

Cor Ligthert [MVP]

VVenk,

You have not instanced your
Dim liTemp As System.DBNull

Probably
Dim liTemp As System.DbNull = Nothing

Will give you the result you want.

However I use direct dbnull.Value

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
You have not instanced your

Probably
Dim liTemp As System.DbNull = Nothing

I assume you wanted to write '... As DBNull = DBNull.Value'.
 
C

Cor Ligthert [MVP]

Herfried,

I saw everybody giving the same answers as Bill did.

Therefore I thought I do the same, however you know if I do that, it has to
be an addition or something else.

I was thinking on your option, however the one I gave did look for me even
more different.

Therefore I tested it before and had the idea that it was working.

:)

Cor
 

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