Groups | Blog | Home
all groups > vb.net data > september 2005 >

vb.net data : DataBinding to table with null values


daniel kurtz
9/26/2005 4:44:26 PM
VS2003. Have datagrid with drop down list, who's selectedindex property is
bound to an int32 column in an ODBC dataset. Problem is that many rows in
this dataset have (incorrectly) a null value in this column, which is
causing an invalid cast error upon binding. Is there a way to force the
binding to treat the null value as zero, or an ODBC SQL function that will
convert the nulls to zeroes during the select?

Jim Underwood
11/3/2005 12:00:00 AM
Oracle uses NVL(FieldName,DefaultValue) to deal with nulls

I dont know of a comparable SQL method, but you can create your own easily
enough...

CREATE FUNCTION dbo.NVLint
(@intVal numeric,
@returnval numeric)
RETURNS numeric AS
BEGIN
declare @MyValue numeric
if @intVal is null
set @MyValue = @returnval
else
set @MyValue = @intval
return @MyValue
END

The above function will work only for numeric types, or types that can
convert to numeric.

select dbo.NVLint(Field1,0) from Table

[quoted text, click to view]

AddThis Social Bookmark Button