René Stalder René Stalder - 1 year ago 263
SQL Question

C# SQL Data Adapter System.Data.StrongTypingException

I get my data from SQL to Dataset with Fill. It's just one table with two columns (CategoryId (int) and CategoryName (varchar)).

When I look at my dataset after fill method, CategoryId Columns seems to be correct. But in the CategoryName I have a *System.Data.StrongTypingExceptio*n.

What could that mean?

Any Ideas?

Answer Source

When you get the value of a row/column in a typed dataset, by default it raises this exception when the value is DBNull. So

string x = Row.CategoryName;//Raises this exception when CategoryName is null.

You can correct this with the typed dataset designer.
Set the property "Nullvalue" of the CategroyName column to "(Empty)"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download