Help with DBNUll

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
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
 
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'.
 
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
 
Back
Top