Convert.IsDBNull causes exception

  • Thread starter Thread starter Rainer Queck
  • Start date Start date
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
 
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
}
 
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
 
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
 
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
 
Back
Top