473,699 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invalid cast from System.Int32 to System.Byte[].

Hi,
I got a stored procedure, where it returns a value. But if I execute it. It
gives an error as "Invalid cast from System.Int32 to System.Byte[].". To make
clear how do I execute this, below I'm specifiying my code:

The Code used in Visual Studio:

Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As
String, ByVal iDate As Date) As String
'Dim Ret As Integer
Dim oCm As New SqlCommand("spG etShareholderRa nk", connection)
'@ID as VarChar, @Comp as VarChar, @iDate as DateTime, @sec as Varchar

oCm.CommandType = CommandType.Sto redProcedure
oCm.Parameters. Add(New SqlParameter("R ETURN_VALUE",
ParameterDirect ion.Output, SqlDbType.Int))
oCm.Parameters. Add(New SqlParameter("@ ID", ParameterDirect ion.Input,
SqlDbType.Int)) .Value = ID
oCm.Parameters. Add(New SqlParameter("@ Comp",
ParameterDirect ion.Input, SqlDbType.VarCh ar)).Value = Comp
oCm.Parameters. Add(New SqlParameter("@ iDate",
ParameterDirect ion.Input, SqlDbType.DateT ime)).Value = iDate
oCm.Parameters. Add(New SqlParameter("@ sec",
ParameterDirect ion.Input, SqlDbType.VarCh ar)).Value = Sec

Try
oCm.ExecuteNonQ uery()
'Ret = Convert.ToInt32 (oCm.Parameters ("@ret").Val ue)
'If Convert.ToInt32 (oCm.Parameters ("RETURN_VALUE" ).Value) > 0 Then
'Return Convert.ToInt32 (oCm.Parameters ("@ret").Val ue)
If oCm.Parameters( "RETURN_VALUE") .Value.ToString .Length > 0 Then
Return oCm.Parameters( "RETURN_VALUE") .Value.ToString
Else
Return 0
End If
Finally
oCm.Dispose()
End Try
End Function

And this is how I created my Stored Procedure:

CREATE PROCEDURE [spGetShareholde rRank]
@ID Int,
@Comp VarChar(10),
@iDate DateTime,
@sec Varchar(10),
@ret Int OUTPUT
AS
DECLARE @Rank Int

SELECT @ret = ShareBalance.Ra nk
FROM ShareBalance INNER JOIN Lists ON ShareBalance.Li stID = Lists.ListID
WHERE ShareBalance.Sh areHolderNo=@ID
AND Lists.CompID=@C omp
AND Lists.IssueDate = @iDate
AND Lists.SecurityC ode=@sec

IF (@ret) <= 0
SET @ret = 0
GO

Is there anything wrong with my Codes? I did test'd my stored procedure in
Query Analyzer where it worked fine.

Note:
The Error in Detail:
Server Error in '/grid' Application.
Invalid cast from System.Int32 to System.Byte[].
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.InvalidC astException: Invalid cast from
System.Int32 to System.Byte[].
Source Error:
Source File: c:\inetpub\wwwr oot\grid\Differ entiate.aspx.vb Line: 314
Stack Trace:
Version Information: Microsoft .NET Framework Version:1.1.432 2.2032; ASP.NET
Version:1.1.432 2.2032
Line 312:
Line 313: Try
Line 314: oCm.ExecuteNonQ uery()
Line 315: 'Ret = Convert.ToInt32 (oCm.Parameters ("@ret").Val ue)
Line 316: If Convert.ToInt32 (oCm.Parameters ("@ret").Val ue) > 0 Then
[InvalidCastExce ption: Invalid cast from System.Int32 to System.Byte[].]
System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or cmdBehavior,
RunBehavior runBehavior, Boolean returnStream) +742
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery()
grid.Differenti ate.GetRank(Int 32 ID, String Comp, String Sec, DateTime
iDate) in c:\inetpub\wwwr oot\grid\Differ entiate.aspx.vb :314
grid.Differenti ate.Submitbtn_C lick(Object sender, EventArgs e) in
c:\inetpub\wwwr oot\grid\Differ entiate.aspx.vb :158
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl,
String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
System.Web.UI.P age.ProcessRequ estMain() +1292
Page 1 of 1 Invalid cast from System.Int32 to System.Byte[].

Regards,

--
Mohammed Hifni Shahzard Nazeer,
JB Securities Pvt. Ltd.,
Colombo.
Nov 19 '05 #1
1 4898
In your stored procedure you have a parameter called @Ret int OUTPUT. You
are never creating the @ret output parameter.

oCm.Parameters. Add(New SqlParameter("@ ret", ParameterDirect ion.Output,
SqlDbType.Int))

When you get the value back out, you can directly cast this.

Dim ret as int;
ret = CType( oCm.Parameters( "@ret").Val ue, int )

HTH,

bill

"Hifni Shahzard" <Hi***********@ discussions.mic rosoft.com> wrote in message
news:90******** *************** ***********@mic rosoft.com...
Hi,
I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte[].". To make clear how do I execute this, below I'm specifiying my code:

The Code used in Visual Studio:

Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As
String, ByVal iDate As Date) As String
'Dim Ret As Integer
Dim oCm As New SqlCommand("spG etShareholderRa nk", connection)
'@ID as VarChar, @Comp as VarChar, @iDate as DateTime, @sec as Varchar
oCm.CommandType = CommandType.Sto redProcedure
oCm.Parameters. Add(New SqlParameter("R ETURN_VALUE",
ParameterDirect ion.Output, SqlDbType.Int))
oCm.Parameters. Add(New SqlParameter("@ ID", ParameterDirect ion.Input, SqlDbType.Int)) .Value = ID
oCm.Parameters. Add(New SqlParameter("@ Comp",
ParameterDirect ion.Input, SqlDbType.VarCh ar)).Value = Comp
oCm.Parameters. Add(New SqlParameter("@ iDate",
ParameterDirect ion.Input, SqlDbType.DateT ime)).Value = iDate
oCm.Parameters. Add(New SqlParameter("@ sec",
ParameterDirect ion.Input, SqlDbType.VarCh ar)).Value = Sec

Try
oCm.ExecuteNonQ uery()
'Ret = Convert.ToInt32 (oCm.Parameters ("@ret").Val ue)
'If Convert.ToInt32 (oCm.Parameters ("RETURN_VALUE" ).Value) > 0 Then 'Return Convert.ToInt32 (oCm.Parameters ("@ret").Val ue)
If oCm.Parameters( "RETURN_VALUE") .Value.ToString .Length > 0 Then Return oCm.Parameters( "RETURN_VALUE") .Value.ToString
Else
Return 0
End If
Finally
oCm.Dispose()
End Try
End Function

And this is how I created my Stored Procedure:

CREATE PROCEDURE [spGetShareholde rRank]
@ID Int,
@Comp VarChar(10),
@iDate DateTime,
@sec Varchar(10),
@ret Int OUTPUT
AS
DECLARE @Rank Int

SELECT @ret = ShareBalance.Ra nk
FROM ShareBalance INNER JOIN Lists ON ShareBalance.Li stID = Lists.ListID
WHERE ShareBalance.Sh areHolderNo=@ID
AND Lists.CompID=@C omp
AND Lists.IssueDate = @iDate
AND Lists.SecurityC ode=@sec

IF (@ret) <= 0
SET @ret = 0
GO

Is there anything wrong with my Codes? I did test'd my stored procedure in
Query Analyzer where it worked fine.

Note:
The Error in Detail:
Server Error in '/grid' Application.
Invalid cast from System.Int32 to System.Byte[].
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidC astException: Invalid cast from
System.Int32 to System.Byte[].
Source Error:
Source File: c:\inetpub\wwwr oot\grid\Differ entiate.aspx.vb Line: 314
Stack Trace:
Version Information: Microsoft .NET Framework Version:1.1.432 2.2032; ASP.NET Version:1.1.432 2.2032
Line 312:
Line 313: Try
Line 314: oCm.ExecuteNonQ uery()
Line 315: 'Ret = Convert.ToInt32 (oCm.Parameters ("@ret").Val ue)
Line 316: If Convert.ToInt32 (oCm.Parameters ("@ret").Val ue) > 0 Then
[InvalidCastExce ption: Invalid cast from System.Int32 to System.Byte[].]
System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +742
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery()
grid.Differenti ate.GetRank(Int 32 ID, String Comp, String Sec, DateTime
iDate) in c:\inetpub\wwwr oot\grid\Differ entiate.aspx.vb :314
grid.Differenti ate.Submitbtn_C lick(Object sender, EventArgs e) in
c:\inetpub\wwwr oot\grid\Differ entiate.aspx.vb :158
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP o
stBackEvent(Str ing eventArgument) System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl,
String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
System.Web.UI.P age.ProcessRequ estMain() +1292
Page 1 of 1 Invalid cast from System.Int32 to System.Byte[].

Regards,

--
Mohammed Hifni Shahzard Nazeer,
JB Securities Pvt. Ltd.,
Colombo.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2673
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
3
2288
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring =
0
595
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
0
1481
by: Robert Smith | last post by:
I am getting the following error being caught in my application_error method... I have no code referencing the crypto classes. I have found nothing on the net outside of people with crypto issues. Please Help. ~rob Padding is invalid and cannot be removed. at
2
6156
by: Brent K | last post by:
Ok, I have an internal intranet website created in visual studio 2005, c#. It was running fine for months, and then all of the sudden a few days I started getting these errors emailed to me (I have it set up to email me exceptions). Here is the error. I have gotten this error probably 100 times in the last 2 days. I have googled this error to no avail. My program is not doing any decrypting, I am not on a web farm, I have reset the web...
1
8588
by: rdlauer | last post by:
For some time now we've been seeing seemingly random errors thrown by an application "Padding is invalid and cannot be removed". Everything I've read about this online suggests that the machine key is different between two load-balanced servers, but this application is running on just one server. The other odd thing is that the errors come in groups. Over a short period of time (5 minutes or so) many different users will hit this error...
0
3372
by: Amelyan | last post by:
Why does this happen? How to fix it? Once in a while I get error in ~/ScriptResource.axd?d=... System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. at
4
8450
by: MC | last post by:
Could someone please explain why I get 10-15 errors a day from my site after the "googleBot" has visited? Regards MC --------Error--------- Padding is invalid and cannot be removed. --------Stack Trace--------- Current Path:/WebResource.axd
9
2534
by: AG | last post by:
I occassionally get the following exception from an ASP.NET 2.0 Web Application running on a shared web host. I have no way of knowing what the actual request page was as it never happens when I visit the site. The exception is trapped in the Application_Error event of global.asax and emailed to me. The only encryption in the app is the connectionStrings section of web.config.
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8940
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7781
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.