質問

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?

役に立ちましたか?

解決

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

他のヒント

Can you check it from this?

accountFilter.Fields["Currency_ID"]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top