Convert.IsDBNull causes exception

R

Rainer Queck

Hello NG,

I have a typed dataset, where I want to check the column of a datarow if it
is DBNull.
How can the following code cause an Exception (what is does):

if (Convert.IsDBNull(myDataRow.vrAbarbeitung))
{
....
}
When this code is called I get the Exception :
"Der Wert für Spalte vrAbarbeitung in Tabelle tblVersuchsreihe ist DBNull."
which translated to english is:
"The Value for the column vrAbarbeitung in table tblVersuchsreihe is DBNull"

Somehow this irritates me...

Regards
Rainer Queck
 
M

Manu Singhal

Hello

If you are using a typed dataset you should use following code to check if
the column value in a given row is DBNull

if(myDataRow.IsvrAbarbeitungNull())

{
// any code that should be run if the column value is DBNull
}
 
M

Marc Gravell

How is vrAbarbeitung defined on the datarow? If this is (for instance)
an int, then it was have no chance of invoking theproperty, as it
can't cast DBNull to an int. You may need to use an object form - i.e.

myDataRow["vrAbarbeitung"] (depending on what the column is actually
called, as opposed to the property-name)

Marc
 
R

Rainer Queck

Hi Manu,
if(myDataRow.IsvrAbarbeitungNull())
Yes, that works OK.
Still I am wondering, why "Convert.IsDBNull(myDataRow.vrAbarbeitung)"
fails....

Well, maybe that is a "ToDo" in the Framework ;-)

Thanks for your help!

Regards
Rainer
 
M

Marc Gravell

Still I am wondering, why "Convert.IsDBNull(myDataRow.vrAbarbeitung)"
fails....

It is equivalent to (using int as an example)

int tmp = myDataRow.vrAbarbeitung;
.... Convert.IsDBNull(tmp);

the first line *must* throw, since (as before) you can't cast DBNull
to many things

Marc
 

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