Home All Groups Group Topic Archive Search About

Conversion from type 'SqlInt32' to type 'Integer' is not valid

Author
31 Oct 2005 5:55 PM
Greg Burns
I have a lot of autogenerated code (created from LLBL Gen,
http://www.sd.nl/software/)  that looks similiar to this:

Dim _errorCode As SqlInt32
....
_errorCode = New
SqlInt32(CType(cmdToExecute.Parameters.Item("@iErrorCode").Value, Integer))

I am upgrading my project to VS 2005.  Now, when this code executes I am
getting a run-time error where I did not before.  The value of @iErrorCode
is 0, not null.

System.InvalidCastException occurred
System.InvalidCastException: Conversion from type 'SqlInt32' to type
'Integer' is not valid.

Simple fix seems to be to change the code to this:

_errorCode = CType(cmdToExecute.Parameters.Item("@iErrorCode").Value,
SqlInt32)

What has changed in VB 2005 that is causing this?

Thanks,
Greg

Author
31 Oct 2005 10:44 PM
Frans Bouma [C# MVP]
Greg Burns wrote:

Show quote
> I have a lot of autogenerated code (created from LLBL Gen,
> http://www.sd.nl/software/)  that looks similiar to this:
>
> Dim _errorCode As SqlInt32
> ...
> _errorCode = New
> SqlInt32(CType(cmdToExecute.Parameters.Item("@iErrorCode").Value,
> Integer))
>
> I am upgrading my project to VS 2005.  Now, when this code executes I
> am getting a run-time error where I did not before.  The value of
> @iErrorCode is 0, not null.
>
> System.InvalidCastException occurred
> System.InvalidCastException: Conversion from type 'SqlInt32' to type
> 'Integer' is not valid.
>
> Simple fix seems to be to change the code to this:
>
> _errorCode = CType(cmdToExecute.Parameters.Item("@iErrorCode").Value,
> SqlInt32)
>
> What has changed in VB 2005 that is causing this?

    I've no idea, the main thing what was not possible in vs.net 2003 was
the implicit conversion operator usage by VB.NET between sqlint32 and
integer. In vs.net 2005 this is available in VB.NET, perhaps it invokes
these implicit conversions now.

        FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Author
31 Oct 2005 11:36 PM
Greg Burns
Thanks for the input.

Greg

Show quote
"Frans Bouma [C# MVP]" <perseus.usenetNOSPAM@xs4all.nl> wrote in message
news:xn0e95ru3lwneg000@news.microsoft.com...
> Greg Burns wrote:
>
>> I have a lot of autogenerated code (created from LLBL Gen,
>> http://www.sd.nl/software/)  that looks similiar to this:
>>
>> Dim _errorCode As SqlInt32
>> ...
>> _errorCode = New
>> SqlInt32(CType(cmdToExecute.Parameters.Item("@iErrorCode").Value,
>> Integer))
>>
>> I am upgrading my project to VS 2005.  Now, when this code executes I
>> am getting a run-time error where I did not before.  The value of
>> @iErrorCode is 0, not null.
>>
>> System.InvalidCastException occurred
>> System.InvalidCastException: Conversion from type 'SqlInt32' to type
>> 'Integer' is not valid.
>>
>> Simple fix seems to be to change the code to this:
>>
>> _errorCode = CType(cmdToExecute.Parameters.Item("@iErrorCode").Value,
>> SqlInt32)
>>
>> What has changed in VB 2005 that is causing this?
>
> I've no idea, the main thing what was not possible in vs.net 2003 was
> the implicit conversion operator usage by VB.NET between sqlint32 and
> integer. In vs.net 2005 this is available in VB.NET, perhaps it invokes
> these implicit conversions now.
>
> FB
>
> --
> ------------------------------------------------------------------------
> Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
> My .NET blog: http://weblogs.asp.net/fbouma
> Microsoft MVP (C#)
> ------------------------------------------------------------------------

AddThis Social Bookmark Button