I have a dataset that I want to update. I pull the row out that I want
to update. There is a value in one of the columns that must be
analized to determine if other values need to change. This works great
as long as there is something in that column. If that DB column is
empty, I get this error...

"System.Data.StrongTypingException: Cannot get value because it is
DBNull. ---> System.InvalidCastException: Cast from type 'DBNull' to
type 'Decimal' is not valid.

I have tried all sorts of things.
I am wanting to get like, row.CCNum
THis is great unless CCNumis empty. I've tried the method
isDBNull(row.CCNum), but I still get the same error. How do I return a
value from a DB and not error out if its empty? I have multiple
columns to update, so I don't want to use an execute reader. I would
like to use the 'row' type methods to get this done.

Re: retrieve a column value from a row that might be DBNull by rew190

rew190
Tue Oct 25 12:15:20 CDT 2005

Is your dataset typed? (I'm assuming so because of the reference to
row.CCNum).

If so, you should have an auto-generated method "isCCNumNull()" method.
Use that instead.


Re: retrieve a column value from a row that might be DBNull by W

W
Tue Oct 25 12:17:58 CDT 2005

Marty, you can just check it with
(IsDbNull(tablename.Rows[index][ColumnIndexorName])) ? WhateverDefaultvalue
: tablename.rows[index][ColumnIndexorName]; but if I understand you
correctly, this is what you're doing. I don't know if there's a cast or
something else in the expression, but here's an article that walks you
through it in depth.

http://www.knowdotnet.com/articles/handlingnullvalues.html

HTH,

Bill
<marty.overdear@intergraph.com> wrote in message
news:1130258663.300330.246750@z14g2000cwz.googlegroups.com...
>I have a dataset that I want to update. I pull the row out that I want
> to update. There is a value in one of the columns that must be
> analized to determine if other values need to change. This works great
> as long as there is something in that column. If that DB column is
> empty, I get this error...
>
> "System.Data.StrongTypingException: Cannot get value because it is
> DBNull. ---> System.InvalidCastException: Cast from type 'DBNull' to
> type 'Decimal' is not valid.
>
> I have tried all sorts of things.
> I am wanting to get like, row.CCNum
> THis is great unless CCNumis empty. I've tried the method
> isDBNull(row.CCNum), but I still get the same error. How do I return a
> value from a DB and not error out if its empty? I have multiple
> columns to update, so I don't want to use an execute reader. I would
> like to use the 'row' type methods to get this done.
>



Re: retrieve a column value from a row that might be DBNull by marty

marty
Tue Oct 25 12:28:58 CDT 2005

The auto-generated method "isCCNumNull" is there and worked great. Thx
for the info, had no clue it existed. I was trying the isdbnull stuff,
but couldn't get it to work out for me


Re: retrieve a column value from a row that might be DBNull by rew190

rew190
Tue Oct 25 12:38:33 CDT 2005

Cool, glad that did it for you.

As an aside, there is also a SetCCNumNull() method that's
auto-generated that will set your field to DBNull.