Null Casting Error when using Strongly-Typed Dataset

C

C Newby

I have a strongly-typed dataset containing a table that contains a field
that is nullable. I can fill this table without a problem. However, when
accessing the nullable field such as:

String something = MyStronglyTypedDS.SomeTable[
0 ].SomeRow.SomeNullableField

I get a "Specified cast is not valid" exception if the content of the field
is null. If it contains data there is no problem. When i looked at the code
behind for the dataset's XSD, I could see what was happening:

public string SomeNullableField{
get {
try {
return
((string)(this[this.tableSomeTable.SomeNullableFieldColumn]));
}
catch (InvalidCastException e) {
throw new StrongTypingException("Cannot get value
because it is DBNull.", e);
}
}
set {
this[this.tableSomeTable.SomeNullableFieldColumn] =
value;
}
}

Ok ... so either i'm doing something wrong or i'm not understanding
something. If the field is DBNull, why isn't it just reissued as a framework
null?

TIA//
 
C

C Newby

In answer to my own question:

MyStronglyTypedDS.SomeTable[ 0 ].SomeRow.IsSomeNullableFieldNull()

:)

Thanks got to my friend Sean McIassac with Intwine.
 

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