empty DataTable fields throw exception

  • Thread starter Thread starter Edward Bills
  • Start date Start date
E

Edward Bills

I'm having some trouble with a typed dataset that contains fields that
should technically be considered null. I've loaded my typed dataset from SQL
server. One particular table contains only one row. It has two fields:
Agency and CaseType. In the SQL Server table, the Agency field has a value,
but the CaseType field is null. In my typed dataset, I can read the Agency
value, but any attempt I have made to read, validate, or even reference the
CaseType field throws a runtime exception.

What am I missing? How can I check to see if this field is empty before I
try and use it? I realize that I can deal with this by throwing a Try Catch
around every place where I do anything with my fields, but as you can see
that sounds pretty silly.

Help?

Thanks.
 
Hi Edward,

There are Is[FieldName]Null methods in strong typed datasets for each column
that allows null values.
You can't use the property (as you've found out) as it casts the value.
 
That solved my problem thanks.

Miha Markic said:
Hi Edward,

There are Is[FieldName]Null methods in strong typed datasets for each column
that allows null values.
You can't use the property (as you've found out) as it casts the value.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Edward Bills said:
I'm having some trouble with a typed dataset that contains fields that
should technically be considered null. I've loaded my typed dataset from SQL
server. One particular table contains only one row. It has two fields:
Agency and CaseType. In the SQL Server table, the Agency field has a value,
but the CaseType field is null. In my typed dataset, I can read the Agency
value, but any attempt I have made to read, validate, or even reference the
CaseType field throws a runtime exception.

What am I missing? How can I check to see if this field is empty before I
try and use it? I realize that I can deal with this by throwing a Try Catch
around every place where I do anything with my fields, but as you can see
that sounds pretty silly.

Help?

Thanks.
 
Back
Top