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//
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//