混合1.1和2.0环境中的问题转换 [英] Problem casting in mixed 1.1 and 2.0 environment

查看:67
本文介绍了混合1.1和2.0环境中的问题转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个令人讨厌的问题,因为我在一个2.0应用程序中包含了一个已创建的DAL中的一个强制转换器。$ / $

我们系统中的每个存储过程使用整数参数来返回错误

代码。以下代码在1.1应用程序中运行良好,从我在完全2.0应用程序中制作的测试应用程序

。但是,当我尝试使用来自2.0应用程序的DAL时,
使用1.1编译的DAL,以下转换会抛出无效的转换

异常(System.InvalidCastException:Specified cast无效。)


cmdToExecute.Parameters.Add(new SqlParameter(" @ iErrorCode",SqlDbType.Int,

4,ParameterDirection.Output ,true,10,0,",,DataRowVersion.Proposed,

_errorCode));


con.Open();


//执行查询。

adapter.Fill(toReturn);

_errorCode =(Int32)cmdToExecute.Parameters [" @ iErrorCode" ] .Value;


是否有人能够确认这是否是框架中的错误,预期

行为或其他?


问候

Mark

Hi,

I have this annoying problem with a cast failing from a DAL that was created
in 1.1 that I have included in a 2.0 app.

Every stored proc in our system uses an integer parameter to return an error
code. The following code works fine in 1.1 apps, and from a test app I made
in fully 2.0 apps. However, when I try to use the DAL from a 2.0 app that
uses the 1.1 compiled DAL, the following cast throws an invalid cast
exception (System.InvalidCastException: Specified cast is not valid.)

cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int,
4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed,
_errorCode));

con.Open();

// Execute query.
adapter.Fill(toReturn);
_errorCode = (Int32)cmdToExecute.Parameters["@iErrorCode"].Value;

Is anyone able to confirm if this is a bug in the Framework, expected
behaviour, or otherwise?

Regards
Mark

推荐答案

" Tyler Durden" < MS ******** @ aspect.com.au>在留言新闻中写道:5D ********************************** @ microsof t.com ...
"Tyler Durden" <ms********@aspect.com.au> wrote in message news:5D**********************************@microsof t.com...
cmdToExecute.Parameters.Add(new SqlParameter(" @ iErrorCode",SqlDbType.Int,
:: _ _ errorCode =(Int32)cmdToExecute.Parameters [" @ iErrorCode"]。Value;

是否有人能够确认这是否是框架中的错误,预期的行为或其他?
cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, : : _errorCode = (Int32)cmdToExecute.Parameters["@iErrorCode"].Value;

Is anyone able to confirm if this is a bug in the Framework, expected
behaviour, or otherwise?




当发生什么时候会发生什么?你说,


cmdToExecute.Parameters [" @ iErrorCode"]。Value.GetType().FullName





我相信在.NET 2.0下,这将永远是一个SqlInt32(它是Nullable,在2.0中是一个新的概念
,因此它是否具有DBNull值,它总是

是这个特定类型),区别于.NET 1.x,其中此参数

值可以是Int32或DBNull.Value(即,打字在空中

我认为这导致了不那么强烈的打击,效率低下nt IL in 1.x.)

Derek Harmon



What happens when you say,

cmdToExecute.Parameters["@iErrorCode"].Value.GetType( ).FullName

?

I believe under .NET 2.0, this will always be a SqlInt32 (which is Nullable, a
new concept in 2.0, thus whether it has a DBNull value or not, it will always
be this one specific type), distinguished from .NET 1.x where this parameter
value could be an Int32 or a DBNull.Value (i.e., the typing was up in the air
and I believe this led to less strongly-typed, less-efficient IL in 1.x.)
Derek Harmon


嗨Derek


如果我理解正如你所说的那样,我认为这意味着演员在2.0环境下也无法工作。事实是它在一个完全1.1编译的应用程序中,以及在完全2.0

编译的应用程序中确实有效,但在使用两者的混合时则不行。


因此,根据您的回复,我会假设由于更强的输入规则,该类型的演员将在2.0框架中不成功。或者是

我错过了什么?


问候,

马克


" ; Derek Harmon写道:
Hi Derek

If I understand what you are saying correctly, I would think that would mean
the cast would not work in the 2.0 environment either. The fact is that it
does work when in a completely 1.1 compiled app, and also in a completely 2.0
compiled app, but not when use a mixture of both.

Therefore, from your response I would assume that a cast of that type would
not succeed in the 2.0 framework because of the stronger typing rules. Or am
I missing something?

Regards,
Mark

"Derek Harmon" wrote:
" Tyler Durden" < MS ******** @ aspect.com.au>在留言新闻中写道:5D ********************************** @ microsof t.com ...
"Tyler Durden" <ms********@aspect.com.au> wrote in message news:5D**********************************@microsof t.com...
cmdToExecute.Parameters.Add(new SqlParameter(" @ iErrorCode",SqlDbType.Int,
cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int,


::


: :

_errorCode =(Int32)cmdToExecute。参数[" @ iErrorCode"]。值;

是否有人能够确认这是否是框架中的错误,预期的行为或其他?
_errorCode = (Int32)cmdToExecute.Parameters["@iErrorCode"].Value;

Is anyone able to confirm if this is a bug in the Framework, expected
behaviour, or otherwise?


当你说,

cmdToExecute.Parameters [" @ iErrorCode"]时会发生什么.Value.GetType()。FullName



我相信在.NET 2.0下,这将永远是一个SqlInt32(它是Nullable,是2.0中的一个新概念,因此它是否具有DBNull值,它总是会成为这一个特定的类型),区别于.NET 1.x,其中此参数值可以是Int32或DBNull.Value(即打字在空中
我相信这导致不太强烈的类型,更少的e 1.x中的有效IL。)

Derek Harmon



What happens when you say,

cmdToExecute.Parameters["@iErrorCode"].Value.GetType( ).FullName

?

I believe under .NET 2.0, this will always be a SqlInt32 (which is Nullable, a
new concept in 2.0, thus whether it has a DBNull value or not, it will always
be this one specific type), distinguished from .NET 1.x where this parameter
value could be an Int32 or a DBNull.Value (i.e., the typing was up in the air
and I believe this led to less strongly-typed, less-efficient IL in 1.x.)
Derek Harmon



Derek,

SqlInt32在2.0之前的框架中,它与

Nullable< int>不同。 SqlInt32是一个非常相似的结构,但不是与2.0中的Nullable类型相同的



-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Derek Harmon" <螺******* @ msn.com>在消息中写道

news:Ou ************** @ TK2MSFTNGP14.phx.gbl ...
Derek,

SqlInt32 was in the framework before 2.0, and it is different from a
Nullable<int>. SqlInt32 is a structure that is very similar, but not the
same as what is considered a Nullable type in 2.0.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Derek Harmon" <lo*******@msn.com> wrote in message
news:Ou**************@TK2MSFTNGP14.phx.gbl...
" Tyler Durden" < MS ******** @ aspect.com.au>在消息中写道
新闻:5D ********************************** @ microsof t.com。 ..
"Tyler Durden" <ms********@aspect.com.au> wrote in message
news:5D**********************************@microsof t.com...
cmdToExecute.Parameters.Add(new SqlParameter(" @ iErrorCode",
SqlDbType.Int,
cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode",
SqlDbType.Int,


::


: :

_errorCode =(Int32)cmdToExecute.Parameters [" @ iErrorCode"]。值;

是否有人能够确认这是否是框架中的错误,预期的行为或其他行为?
_errorCode = (Int32)cmdToExecute.Parameters["@iErrorCode"].Value;

Is anyone able to confirm if this is a bug in the Framework, expected
behaviour, or otherwise?



当你说,

cmdToExecute.Parameters [" @ iErrorCode"]时会发生什么.Value.GetType()。FullName



我相信在.NET 2.0下,这将永远是一个SqlInt32(它是Nullable,在2.0中是一个新概念,因此它是否有一个DBNull是否值,它将始终是这一特定类型),区别于.NET 1.x,其中此值
值可以是Int32或DBNull.Value (即,打字在
空中
我相信这一点导致1.x中强度较低,效率较低的IL。)

Derek Harmon



What happens when you say,

cmdToExecute.Parameters["@iErrorCode"].Value.GetType( ).FullName

?

I believe under .NET 2.0, this will always be a SqlInt32 (which is
Nullable, a
new concept in 2.0, thus whether it has a DBNull value or not, it will
always
be this one specific type), distinguished from .NET 1.x where this
parameter
value could be an Int32 or a DBNull.Value (i.e., the typing was up in the
air
and I believe this led to less strongly-typed, less-efficient IL in 1.x.)
Derek Harmon



这篇关于混合1.1和2.0环境中的问题转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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