C#SQL数据适配器System.Data.StrongTypingException [英] C# SQL Data Adapter System.Data.StrongTypingException

查看:156
本文介绍了C#SQL数据适配器System.Data.StrongTypingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据从SQL获取到具有Fill的数据集.这只是一张有两列(CategoryId(int)和CategoryName(varchar))的表.

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

当我使用fill方法查看数据集时,CategoryId Columns似乎是正确的.但是在CategoryName中,我有一个 System.Data.StrongTypingExceptio n.

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.

那是什么意思?

有什么想法吗?

推荐答案

当您获得类型化数据集中的行/列的值时,默认情况下,当值为DBNull时会引发此异常.所以

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.

您可以使用类型化的数据集设计器来更正此问题.
将CategroyName列的属性空值"设置为(空)"

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

这篇关于C#SQL数据适配器System.Data.StrongTypingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆