如何解决“无法将system.Dbnull转换为类型System.String” [英] How to resolve "unable to cast system.Dbnull to type System.String

查看:433
本文介绍了如何解决“无法将system.Dbnull转换为类型System.String”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,

早上,我遇到了棘手的问题,即我使用的是Asp.net 4(VS 2010)和Mysql(5.5)

我的项目。在Mysql中创建了三个表并通过服务器资源管理器将它连接到.Net现在我可以看到这三个表,请注意到现在还没有编写任何代码但是尽快我右键单击表名并单击刷新突然我收到一个错误框说

无法将System.DbNull类型的对象强制转换为System.string请不要使用示例数据库代码我如何创建表格



Hello Guys,
morning, i got stuck with of the freaking problem i.e. am using Asp.net 4 (VS 2010) and Mysql(5.5)
for one of My project. created three tables in Mysql and connected it to .Net via server explorer
now i can see those three tables , please note have not written any code till now but as soon as i right click on table name and click refresh suddenly i get a error box saying
"Unable to cast object of type System.DbNull to System.string" and please not the sample DB code how i created my table

CREATE TABLE admintable( adminid int NOT NULL primary key,
password varchar(30));





这里的图像是< img src =http://i.imgur.com/cuv0XsY.jpg? 1alt =title =托管b y imgur.com/>

这是我在这里提到过的一张桌子,请有任何帮助我解决这个问题,因为我的时间不多了请

问候

sam



here is the image <img src="http://i.imgur.com/cuv0XsY.jpg?1" alt="" title="Hosted by imgur.com" />
this is one table which i have mentioned here, please any out there help me to resolve this as am running out of time please
regards
sam

推荐答案

这是一个很常见的问题,因为DBNull和Null基本上是一样的,但不是相同的类型。

有一个很好的 stackoverflow.com thread [ ^ ]这应该可以帮助你解决这个问题。



欢呼,

Marco
It is a quite common problem, because DBNull and Null basically mean the same, but are not the same type.
There is a good stackoverflow.com thread[^] which should help you how you can resolve this.

cheers,
Marco


这篇关于如何解决“无法将system.Dbnull转换为类型System.String”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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