i don't think there's an option or function in .net that will handle it for
you. you could create your own to handle various types with an option to
return a default value like this psuedo code:
function getDbValue(byval column as field, byval type as db.datatypes, byval
default as string) as object
on error resume next
if not isnull(column.value) return column.value
return ctype(default, type)
end function
*remember the above i *psuedo* code...b4 i get a million flames about the
details.
another route would be to overload the above function, removing the "type"
argument and setting the "default" to int16, int32, long, string, boolean,
etc. for each type of data you need to deal w/...i think the above would
save a lot of proc time when resolving which version vb should use and,
you'd be saving a ton of space in your code project.
the other option, if you have access and aproval, is to handle it w/n the
db.
queries, views, etc. should use:
sql server: isnull(myColumn, dbo.Zero)
oracle: nvl(myColumn, 0)
or in the table def, make the column "DEFAULT 0".
hth,
steve
"Joćo Roberto Alonso" <al******@kbonet.com.br> wrote in message
news:ud**************@tk2msftngp13.phx.gbl...
Hi
I wanto to know if there is a way to convert a DBNull.Value to Decimal and
returns to me Decimal.Zero?
Examples
COLUMN1 = NULL from DB
Ex1.: cstr((dt.rows(0).item("COLUMN1"))
returns Error
Ex2.: dt.rows(0).item("COLUMN1").toString
returns String.Empty
Ex3.: cdec((dt.rows(0).item("COLUMN1"))
returns Error
Is there a way to return to me Decimal.Zero??
I use this...
cdec((iif(dt.rows(0).item("COLUMN1") is dbnull.value,
decimal.zero,dt.rows(0).item("COLUMN1") ) )