How whould I structure a DBNull statement in a single line???

A

Aaron Ackerman

I want to be able to do the following in a single line.

newDataSetRow.AdditionalHours = if
IsDBNull(vdsPublisherLocal.Tables("CaseInstance").Rows(i).Item("AdditionalHo
urs")) then 0 end if



if the value is null I want to put a valid value in place of the dataset
field, how can i do this?
 
C

Cor

Hi Aaron,

You can using the IIf function, but I find that so bad, that I do not want
to take any time in it.

But if you want to use it, feel free, you just can find is searching for IIf
in MSDN

Cor
 
A

Armin Zingler

Aaron Ackerman said:
I want to be able to do the following in a single line.

newDataSetRow.AdditionalHours = if
IsDBNull(vdsPublisherLocal.Tables("CaseInstance").Rows(i).Item("AdditionalHo
urs")) then 0 end if



if the value is null I want to put a valid value in place of the
dataset field, how can i do this?


if isdbnull(vdsPublisherLocal.Tables( _
"CaseInstance").Rows(i).Item("AdditionalHours"))) then

newDataSetRow.AdditionalHours = 0
end if

Instead of using isdbnull you can compare against DBNull.Value.
 
H

Herfried K. Wagner [MVP]

* "Aaron Ackerman said:
I want to be able to do the following in a single line.

newDataSetRow.AdditionalHours = if
IsDBNull(vdsPublisherLocal.Tables("CaseInstance").Rows(i).Item("AdditionalHo
urs")) then 0 end if

\\\
If ... Then newDataSetRow.AdditionalHours = 0
///
 
P

Phill. W

Aaron Ackerman said:
newDataSetRow.AdditionalHours = if
IsDBNull(vdsPublisherLocal.Tables("CaseInstance").Rows(i).Item("AdditionalHo
urs")) then 0 end if
.. . .
if the value is null I want to put a valid value in place of the dataset
field, how can i do this?

Like this:

newDataSetRow.AdditionalHours _
= IIf( 'LongFieldName' <> DBNull.Value _
, 'LongFieldName' _
, 0 _
)

HTH,
Phill W.
 

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