Home All Groups Group Topic Archive Search About
Author
25 Oct 2007 5:19 PM
Robert E. Flaherty
Using C# 2.0 & SQL Server 2000, have a stored procedure that return 0, 1, or
more rows.  At least one of the columns is a date and it may null.  I have
created an XSD of the output from the stored proc.  The entry for the
nullable date column is "<xs:element name="Sent_Dttm" minOccurs="0"
type="xs:dateTime" nillable="true"></xs:element>".  I copied the XSD to the
C# 2.0 windows app I am developing and it nicely generates a strongly typed
dataset.

The problem is I get an error when attempting to access this column in the
dataset when the value is null:
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public System.DateTime Sent_Dttm {
                get {
                    try {
                        return
((System.DateTime)(this[this.tableOwizCommDoc.Sent_DttmColumn]));
                    }
                    catch (System.InvalidCastException e) {
                        throw new System.Data.StrongTypingException("The
value for column \'Sent_Dttm\' in table \'OwizCommDoc\' is DBNull.", e);
                    }
                }
                set {
                    this[this.tableOwizCommDoc.Sent_DttmColumn] = value;
                }
            }


Checking the properties of this field, I noticed that the "NullValue"
property has a value of "(throw exception)'

Author
25 Oct 2007 8:33 PM
Rachel Appel
In article <F82909CD-DEBB-457A-AC69-DED1C4D72***@microsoft.com>,
RobertEFlahe***@discussions.microsoft.com says...
Show quote
> Using C# 2.0 & SQL Server 2000, have a stored procedure that return 0, 1, or
> more rows.  At least one of the columns is a date and it may null.  I have
> created an XSD of the output from the stored proc.  The entry for the
> nullable date column is "<xs:element name="Sent_Dttm" minOccurs="0"
> type="xs:dateTime" nillable="true"></xs:element>".  I copied the XSD to the
> C# 2.0 windows app I am developing and it nicely generates a strongly typed
> dataset.
>
> The problem is I get an error when attempting to access this column in the
> dataset when the value is null:
> [System.Diagnostics.DebuggerNonUserCodeAttribute()]
>             public System.DateTime Sent_Dttm {
>                 get {
>                     try {
>                         return
> ((System.DateTime)(this[this.tableOwizCommDoc.Sent_DttmColumn]));
>                     }
>                     catch (System.InvalidCastException e) {
>                         throw new System.Data.StrongTypingException("The
> value for column \'Sent_Dttm\' in table \'OwizCommDoc\' is DBNull.", e);
>                     }
>                 }
>                 set {
>                     this[this.tableOwizCommDoc.Sent_DttmColumn] = value;
>                 }
>             }
>
>
> Checking the properties of this field, I noticed that the "NullValue"
> property has a value of "(throw exception)'
>
>
>
>

Robert,
Try checking for System.DbNull before accessing the variable and that
should help you out.
Author
25 Oct 2007 9:11 PM
Jim Rand
This is by design.  The strongly typed dataset will have a method (not
property) IsSent_DttmNull() if the underlying column can be null.

if (!IsSent_DttmNull) {access the value}

Show quote
"Rachel Appel" <n***@example.com> wrote in message
news:MPG.218ac7a7b92c306989680@msnews.microsoft.com...
> In article <F82909CD-DEBB-457A-AC69-DED1C4D72***@microsoft.com>,
> RobertEFlahe***@discussions.microsoft.com says...
>> Using C# 2.0 & SQL Server 2000, have a stored procedure that return 0, 1,
>> or
>> more rows.  At least one of the columns is a date and it may null.  I
>> have
>> created an XSD of the output from the stored proc.  The entry for the
>> nullable date column is "<xs:element name="Sent_Dttm" minOccurs="0"
>> type="xs:dateTime" nillable="true"></xs:element>".  I copied the XSD to
>> the
>> C# 2.0 windows app I am developing and it nicely generates a strongly
>> typed
>> dataset.
>>
>> The problem is I get an error when attempting to access this column in
>> the
>> dataset when the value is null:
>> [System.Diagnostics.DebuggerNonUserCodeAttribute()]
>>             public System.DateTime Sent_Dttm {
>>                 get {
>>                     try {
>>                         return
>> ((System.DateTime)(this[this.tableOwizCommDoc.Sent_DttmColumn]));
>>                     }
>>                     catch (System.InvalidCastException e) {
>>                         throw new System.Data.StrongTypingException("The
>> value for column \'Sent_Dttm\' in table \'OwizCommDoc\' is DBNull.", e);
>>                     }
>>                 }
>>                 set {
>>                     this[this.tableOwizCommDoc.Sent_DttmColumn] = value;
>>                 }
>>             }
>>
>>
>> Checking the properties of this field, I noticed that the "NullValue"
>> property has a value of "(throw exception)'
>>
>>
>>
>>
>
> Robert,
> Try checking for System.DbNull before accessing the variable and that
> should help you out.
Author
25 Oct 2007 9:35 PM
Robert E. Flaherty
The issue is that I'm getting bounced in a section of the code automatically
generated when I add an XSD file to the project.  If I start going in and
changing generated code than I am defeating the advance of the code
generation.

I was hoping that there was a way of influencing the code generation.  Is
there?

Show quote
"Jim Rand" wrote:

> This is by design.  The strongly typed dataset will have a method (not
> property) IsSent_DttmNull() if the underlying column can be null.
>
> if (!IsSent_DttmNull) {access the value}
>
> "Rachel Appel" <n***@example.com> wrote in message
> news:MPG.218ac7a7b92c306989680@msnews.microsoft.com...
> > In article <F82909CD-DEBB-457A-AC69-DED1C4D72***@microsoft.com>,
> > RobertEFlahe***@discussions.microsoft.com says...
> >> Using C# 2.0 & SQL Server 2000, have a stored procedure that return 0, 1,
> >> or
> >> more rows.  At least one of the columns is a date and it may null.  I
> >> have
> >> created an XSD of the output from the stored proc.  The entry for the
> >> nullable date column is "<xs:element name="Sent_Dttm" minOccurs="0"
> >> type="xs:dateTime" nillable="true"></xs:element>".  I copied the XSD to
> >> the
> >> C# 2.0 windows app I am developing and it nicely generates a strongly
> >> typed
> >> dataset.
> >>
> >> The problem is I get an error when attempting to access this column in
> >> the
> >> dataset when the value is null:
> >> [System.Diagnostics.DebuggerNonUserCodeAttribute()]
> >>             public System.DateTime Sent_Dttm {
> >>                 get {
> >>                     try {
> >>                         return
> >> ((System.DateTime)(this[this.tableOwizCommDoc.Sent_DttmColumn]));
> >>                     }
> >>                     catch (System.InvalidCastException e) {
> >>                         throw new System.Data.StrongTypingException("The
> >> value for column \'Sent_Dttm\' in table \'OwizCommDoc\' is DBNull.", e);
> >>                     }
> >>                 }
> >>                 set {
> >>                     this[this.tableOwizCommDoc.Sent_DttmColumn] = value;
> >>                 }
> >>             }
> >>
> >>
> >> Checking the properties of this field, I noticed that the "NullValue"
> >> property has a value of "(throw exception)'
> >>
> >>
> >>
> >>
> >
> > Robert,
> > Try checking for System.DbNull before accessing the variable and that
> > should help you out.
>
>
>
Author
26 Oct 2007 12:02 PM
Cor Ligthert[MVP]
Robert,

If a column allows nulls, then there is in your strongly typed dataset
created a method named as IsTheFieldNameNull()

If the DataBase does not allows Nulls, then it is of course a normal error.

Cor
Author
26 Oct 2007 8:25 PM
Robert E. Flaherty
As I pointed out earlier, the error is occurring in code generated when I
copied an XSD file to my C# 2.0 project.  The line of code that I manually
generated is "ds.Load(rdr, LoadOption.OverwriteChanges, new String[] {
"OwizCommFaxDoc" });" where ds has been defined as an instance of the
strongly typed dataset.

The line from the XSD that defines the offending column is "<xs:element
name="Sent_Dttm" minOccurs="0" type="xs:dateTime"
nillable="true"></xs:element>
" minOccurs="1" type="xs:string"></xs:element>






Show quote
"Cor Ligthert[MVP]" wrote:

> Robert,
>
> If a column allows nulls, then there is in your strongly typed dataset
> created a method named as IsTheFieldNameNull()
>
> If the DataBase does not allows Nulls, then it is of course a normal error.
>
> Cor
>

AddThis Social Bookmark Button