2

I have a StronglyTyped data Row object and I can access it like this.

accountFilter.Currency_ID

Currency_ID (Type of Int) is the row name. AccountFilter is the DataRow. When it gives a value, no problem. But when the column value is NULL, it gives a DBNull Exception. I want to check the value for DBNull but it doesn't work.

bool a = Convert.IsDBNull(accountFilter.Currency_ID.ToString()); //doesnt work

Non of these examples dont work.

Any solution?

2
  • 3
    What do you mean by "doesn't work"? What if you remove the .ToString()? Commented Jan 30, 2013 at 14:14
  • 1
    @RichardEv By "doesn't work" hey says, "it gives a DBNull Exception". Commented Jan 30, 2013 at 15:47

2 Answers 2

4

Normally, a row in a table of a typed data set has a IsXYZNull() method for every nullable column. Have you tried

bool a = accountFilter.IsCurrency_IDNull();

This, however, only works if accountFilter is not of type DataRow but of the specialized data row type from your typed data set.

For example: If you have a typed data set which contains a table named Test, there would be a specialized table class TestTable and a specialized data row class named TestTableRow. If the Test table contained a nullable field TestField, the TestTableRow class would contain a method IsTestFieldNull(), so you could call

bool isnull = testTable[0].IsTestFieldNull();

to determine whether the TestField field in the first row of the TestTable testTable was null.

Note that the following does not work, as the result is not of type TestTableRow but of type DataRow, so you'd have to cast this to TestTableRow:

bool isnull = testTable.Rows[0].IsTestFieldNull(); // Won't compile
bool isnull = ((TestTableRow)testTable.Rows[0]).IsTestFieldNull(); // Will compile because of cast
Sign up to request clarification or add additional context in comments.

Comments

0

Can you check it from this?

accountFilter.Fields["Currency_ID"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.