不了解错误消息(数据库) [英] Don't Understand Error Message (Database)

查看:52
本文介绍了不了解错误消息(数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码引发错误指定的转换无效。


MembershipUser user = Membership.GetUser(userId);

DataSet ds = DataLayer.ExecQueryData(" SELECT * FROM mc_Clients WHERE

UserId =''" + userId.ToString()+"''");

if(ds == null || ds.Tables.Count == 0 || ds.Tables [0] .Rows.Count == 0)

返回null;

ClientEx client = new ClientEx();

client.ClientData = new Client();

client.ClientData.Email = user.UserName;

client.ClientData.UserID = user.ProviderUserKey;

client.ClientData.LastLogin = user.LastLoginDate;

DataRow dr = ds.Tables [0] .Rows [ 0];


// ...


if(!Convert.IsDBNull(dr [" Sex"]))

client.Sex =(int)dr [" Sex"]; < ==错误在这里!


// ...


在数据库表中,Sex的数据类型= smallint和nullable = True,并且

client.Sex的数据类型为int。


如果我试图检查dr [" Sex" ]在调试器中,它显示

a值为0x0000。如果我试图在调试器中检查

中的(int)dr [" Sex"]的内容,它会显示一个关于无法取消装箱的错误(抱歉,我没有

更长的确切文字)。


有什么建议吗?


-

乔纳森伍德

SoftCircuits编程
http://www.softcircuits.com

解决方案

" Jonathan Wood" < jw *** @ softcircuits.com写信息

新闻:%2 ****************** @ TK2MSFTNGP04.phx.gbl .. 。


以下代码引发错误指定的强制转换无效。



是的,它会......


if(!Convert.IsDBNull(dr [" ;性别"]))



if(dr [" Sex"]!= DBNull.Value)


在数据库表中,Sex的数据类型= smallint



因此,Sex字段的值范围可以从-32,768到32,767 ...?
http:// msdn2 .microsoft.com / zh-CN / lib ... 8(SQL.80).aspx

-

Mark Rae

ASP.NET MVP
http://www.markrae.net


client.Sex是什么类型的?看起来不管它是什么,它都不能接受int作为

值。除非(int)dr [" Sex]的转换失败,因为它

本身不是整数。


- Peter

网站: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com

MetaFinder: http://www.blogmetafinder.com

Jonathan Wood写道:


以下代码引发错误指定的演员表无效。


MembershipUser user = Membership .GetUser(userId);

DataSet ds = DataLayer.ExecQueryData(" SELECT * FROM mc_Clients WHERE

UserId =''" + userId.ToString()+" ;''");

if(ds == null || ds.Tables.Count == 0 || ds.Tables [0] .Rows.Count == 0)

返回null;

ClientEx client = new ClientEx();

client.ClientData = new Client();

client .ClientData.Email = user.UserName;

client.ClientData.UserID = user.ProviderUserKey;

client.ClientData.LastLogin = user.LastLoginDate;

DataRow dr = ds.Tables [0] .Rows [0];


// ...


if(! Convert.IsDBNull(dr [" Sex"]))

client.Sex =(int)dr [" Sex"]; < ==错误在这里!


// ...


在数据库表中,Sex的数据类型= smallint和nullable = True,并且

client.Sex的数据类型为int。


如果我试图检查dr [" Sex" ]在调试器中,它显示

a值为0x0000。如果我试图在调试器中检查

中的(int)dr [" Sex"]的内容,它会显示一个关于无法取消装箱的错误(抱歉,我没有

更长的确切文字)。


有什么建议吗?


-

乔纳森伍德

SoftCircuits编程
http://www.softcircuits.com


如上所述,client.Sex是一个int。


-

Jonathan Wood

SoftCircuits编程
http: //www.softcircuits.com


" Peter Bromberg [C#MVP]" < pb ******* @ yahoo.NoSpamMaam.com写信息

news:23 ********************* ************* @ microsof t.com ...


什么类型的client.Sex?看起来不管它是什么,它都不能接受$

作为

值。除非(int)dr [" Sex]的转换失败,因为它

本身不是整数。


- Peter

网站: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com

MetaFinder: http://www.blogmetafinder.com


Jonathan Wood写道:


>以下代码引发错误指定的演员表无效。

MembershipUser user = Membership.GetUser (userId);
DataSet ds = DataLayer.ExecQueryData(" SELECT * FROM mc_Clients WHERE
UserId =''" + userId.ToString()+"''");
if(ds == null || ds.Tables.Count == 0 || ds.Tables [0] .Rows.Count ==
0)
返回null;
ClientEx客户端= new ClientEx();
client.ClientData = new Client();
client.ClientData.Email = user.UserName;
client.ClientData.UserID = user.ProviderUserKey;
client.ClientData.LastLogin = user.LastLoginDate;
DataRow dr = ds.Tables [0] .Rows [0];

// ...
if(!Convert.IsDBNull(dr [" Sex"]))
client.Sex =(int)dr [" Sex"]; < ==错误在这里!

// ...

在数据库表中,Sex的数据类型为= smallint,nullable = True,和
client.Sex的数据类型为int。

如果我试图在调试器中检查dr [" Sex"]的内容,它会显示
值为0x0000。如果我试图在调试器中检查(int)dr [" Sex"]
的内容,它会显示一个关于无法取消包装的错误(抱歉,我没有
更长的时间)确切的文字。

有什么建议吗?

-
Jonathan Wood
SoftCircuits编程
http://www.softcircuits.com


The following code raises the error "Specified cast is not valid."

MembershipUser user = Membership.GetUser(userId);
DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
UserId=''" + userId.ToString() + "''");
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
return null;
ClientEx client = new ClientEx();
client.ClientData = new Client();
client.ClientData.Email = user.UserName;
client.ClientData.UserID = user.ProviderUserKey;
client.ClientData.LastLogin = user.LastLoginDate;
DataRow dr = ds.Tables[0].Rows[0];

// ...

if (!Convert.IsDBNull(dr["Sex"]))
client.Sex = (int)dr["Sex"]; <<== ERROR HERE!

// ...

In the database table, Sex has a data type=smallint and nullable=True, and
client.Sex has a data type of int.

If I attempt to examine the contents of dr["Sex"] in the debugger, it shows
a value of 0x0000. If I attempt to examine the contents of (int)dr["Sex"] in
the debugger, it shows an error about not being able to unbox (sorry I no
longer have the exact text).

Any suggestions?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

解决方案

"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...

The following code raises the error "Specified cast is not valid."

Yes, it would do...

if (!Convert.IsDBNull(dr["Sex"]))

if (dr["Sex"] != DBNull.Value)

In the database table, Sex has a data type=smallint

So the Sex field can have a range of values from -32,768 to 32,767...?
http://msdn2.microsoft.com/en-us/lib...8(SQL.80).aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


What type is client.Sex? Looks like whatever it is, it cannot accept int as a
value. Unless the Convert of the (int)dr["Sex"] is failing because it
itself is not an integer.

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Jonathan Wood" wrote:

The following code raises the error "Specified cast is not valid."

MembershipUser user = Membership.GetUser(userId);
DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
UserId=''" + userId.ToString() + "''");
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
return null;
ClientEx client = new ClientEx();
client.ClientData = new Client();
client.ClientData.Email = user.UserName;
client.ClientData.UserID = user.ProviderUserKey;
client.ClientData.LastLogin = user.LastLoginDate;
DataRow dr = ds.Tables[0].Rows[0];

// ...

if (!Convert.IsDBNull(dr["Sex"]))
client.Sex = (int)dr["Sex"]; <<== ERROR HERE!

// ...

In the database table, Sex has a data type=smallint and nullable=True, and
client.Sex has a data type of int.

If I attempt to examine the contents of dr["Sex"] in the debugger, it shows
a value of 0x0000. If I attempt to examine the contents of (int)dr["Sex"] in
the debugger, it shows an error about not being able to unbox (sorry I no
longer have the exact text).

Any suggestions?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


As stated, client.Sex is an int.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message
news:23**********************************@microsof t.com...

What type is client.Sex? Looks like whatever it is, it cannot accept int
as a
value. Unless the Convert of the (int)dr["Sex"] is failing because it
itself is not an integer.

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Jonathan Wood" wrote:

>The following code raises the error "Specified cast is not valid."

MembershipUser user = Membership.GetUser(userId);
DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
UserId=''" + userId.ToString() + "''");
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count ==
0)
return null;
ClientEx client = new ClientEx();
client.ClientData = new Client();
client.ClientData.Email = user.UserName;
client.ClientData.UserID = user.ProviderUserKey;
client.ClientData.LastLogin = user.LastLoginDate;
DataRow dr = ds.Tables[0].Rows[0];

// ...

if (!Convert.IsDBNull(dr["Sex"]))
client.Sex = (int)dr["Sex"]; <<== ERROR HERE!

// ...

In the database table, Sex has a data type=smallint and nullable=True,
and
client.Sex has a data type of int.

If I attempt to examine the contents of dr["Sex"] in the debugger, it
shows
a value of 0x0000. If I attempt to examine the contents of (int)dr["Sex"]
in
the debugger, it shows an error about not being able to unbox (sorry I no
longer have the exact text).

Any suggestions?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


这篇关于不了解错误消息(数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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