PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET SQL Nulls and Strongly Typed DataSets

Reply

SQL Nulls and Strongly Typed DataSets

 
Thread Tools Rate Thread
Old 03-02-2005, 02:05 AM   #1
Robert Gaston
Guest
 
Posts: n/a
Default SQL Nulls and Strongly Typed DataSets


I've seen posts on this, but never a confirmation that anyone's suggestions
actually worked...

I have a sql stored proc that returns multiple result sets. I used the VS
dataset designer, and just drug the stored proc onto the designer to build
the strongly typed dataset.

One of the resultsets includes nulls in some columns. When I attempt to
fill this dataset using adapter.fill, I get type casting errors on every one
of these null fields during the fill if the type is a value type ( decimal,
double, float, datetime ).

I have edited the xsd, adding the nillable=true attribute to these columns,
and regenerated the dataset, but this does not fix anything.

I can turn off the constraint checking, and perform the fill, but when I
turn constraint checking back on, I get the same exceptions of course.

It seems to me that when the strongly typed dataset class is generated, the
nillable attribute is ignored, although it does generate the IsMyFieldNull
and SetMyFieldNull methods.

Any thoughts on this would be greatly appreciated!
Robert Gaston


  Reply With Quote
Old 05-02-2005, 02:51 AM   #2
Robert Gaston
Guest
 
Posts: n/a
Default Re: SQL Nulls and Strongly Typed DataSets

The solution to this APPEARS to be as follows -
http://msdn.microsoft.com/library/d...ypedDataSet.asp

Since a value type cannot hold a null, you must make some provision for a
default value. You can annotate your xsd field elements using the syntax
codegen:nullValue="x" where x is an actual value, or _throw, _null, or
_empty. _empty will use a value created using the default constructor for
the type, but only for strings, sadly. For value types, you pretty much
have to spell out a value. So your null integer becomes zero, your null
date becomes 01/01/0001, etc.

This is most annoying; I hope someone can post a better solution, besides
maybe "never allow nulls in your database" or "always expose your fields as
objects", or "don't use constraint checking"


"Robert Gaston" <nospam> wrote in message
news:O%230GJTZCFHA.560@TK2MSFTNGP15.phx.gbl...
> I've seen posts on this, but never a confirmation that anyone's
> suggestions actually worked...
>
> I have a sql stored proc that returns multiple result sets. I used the VS
> dataset designer, and just drug the stored proc onto the designer to build
> the strongly typed dataset.
>
> One of the resultsets includes nulls in some columns. When I attempt to
> fill this dataset using adapter.fill, I get type casting errors on every
> one of these null fields during the fill if the type is a value type (
> decimal, double, float, datetime ).
>
> I have edited the xsd, adding the nillable=true attribute to these
> columns, and regenerated the dataset, but this does not fix anything.
>
> I can turn off the constraint checking, and perform the fill, but when I
> turn constraint checking back on, I get the same exceptions of course.
>
> It seems to me that when the strongly typed dataset class is generated,
> the nillable attribute is ignored, although it does generate the
> IsMyFieldNull and SetMyFieldNull methods.
>
> Any thoughts on this would be greatly appreciated!
> Robert Gaston
>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off