Dealing with dbnulls after joins
-
There has to be an easy way!!! If a query containing a left join returns a row where records on the right side of the join are not found, dbnulls are returned to the data set. To detect the dbnulls, I am currently changing the code for the dbnull field property in the .vb file. Isn't there a way to configure the dataset elements so that a dbnull cast exception is not thrown without manually modifying the property code for each field? I would like to be able to specify a null string return for strings, 0 for numerical values, etc. If anyone has some insight into this, I would appreciate s suggestion.
-
There has to be an easy way!!! If a query containing a left join returns a row where records on the right side of the join are not found, dbnulls are returned to the data set. To detect the dbnulls, I am currently changing the code for the dbnull field property in the .vb file. Isn't there a way to configure the dataset elements so that a dbnull cast exception is not thrown without manually modifying the property code for each field? I would like to be able to specify a null string return for strings, 0 for numerical values, etc. If anyone has some insight into this, I would appreciate s suggestion.
I'd say you would be better changing the SQL to return the appropriate value:
SELECT t1.c1 as t1c1, t1.c2 as t1c2, COALESCE(t2.c1, '') as t2c1, COALESCE(t2.c2, 0) as t2c2
FROM ...t2.c1 is a string t2.c2 is an integer For more information look up the index on the SQL Server 2000 books online for COALESCE --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#