user221074 user221074 - 2 months ago 8
C# Question

Get cell value from Dataset

I have Table in Data Set and when i try get cell value if value is null i get exception. Strong Typing Exception
"The value for column Surname in table AI_PARTNERS is Db Null."
Ever time when i try turn


partnersDataSet.AI_PARTNERS[0].SURNAME


if is null i get exception and can't do compare with null.

_partnerInfo.Surname = partnersDataSet.AI_PARTNERS[0].SURNAME


how get the value or empty string if value null?

Answer

You can always use one of the DataRow.IsNull method overloads. Also, since you are using typed data set, there must be a generated method called IsSURNAMENull().

But you can get that automatically. Open the typed dataset xsd file in the designer, select the SURNAME property, go to Properties window and change the NullValue property from (Throw exception) (the default) to either (Null) or (Empty).

Reference: Annotating Typed DataSets

Comments