empty DataTable fields throw exception

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.
 
M

Miha Markic [MVP C#]

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.
 
E

Edward Bills

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top