C# SQL Data Adapter System.Data.StrongTypingException

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-02 09:15:44

问题


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.StrongTypingException.

What could that mean?

Any Ideas?


回答1:


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)"



来源:https://stackoverflow.com/questions/2697210/c-sharp-sql-data-adapter-system-data-strongtypingexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!