problem with sending and returning value in/from stored proc

B

Bob

Hi,

I want to send a parameter (via a request.querystring) to a stored
procedure, which, using that parameter, must then
calculate a scalar value and return it back to the code.

Not sure whether this way is correct because of this error:
"Input string was not in a correct format."
at line: numb = chat.myfunction(Request.QueryString("myparam"))

Maybe i have to use sqldatareader but i don't know how exactly.
Thanks for help
Bob

code-behind:
------------
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
Dim numb As int16
numb = myclass.myfunction(Request.QueryString("myparam"))
Label1.Text = numb
End Sub

myclass.vb (in App_Code)
------------------------
Imports System.Data
Imports System.Data.SqlClient

Public Class test
Public Shared Function myfunction(ByVal ID As Integer) As int16
Dim nb As Int16
Try
Using mConnection As New SqlConnection(param.ConnectionString)
Dim mCommand As SqlCommand = New SqlCommand("mystoredproc",
mConnection)
mCommand.CommandType = CommandType.StoredProcedure
mCommand.Parameters.AddWithValue("@ID", ID)
mConnection.Open()
nb = Convert.ToInt16(mCommand.ExecuteScalar())
mConnection.Close()
mCommand.Dispose()
Return nb
End Using
Catch ex As Exception
Throw
End Try
End Function
End Class

mystoredproc:
-------------
ALTER PROCEDURE [dbo].[mystoredproc]
@ID int
AS
BEGIN
Select COUNT(itemID) from mytable where itemID=@ID
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Bob said:
Hi,

I want to send a parameter (via a request.querystring) to a stored
procedure, which, using that parameter, must then
calculate a scalar value and return it back to the code.

Not sure whether this way is correct because of this error:
"Input string was not in a correct format."
at line: numb = chat.myfunction(Request.QueryString("myparam"))

That means that the querystring value can not be converted to an
integer. This has nothing to do with how you call the stored procedure,
as the code never gets that far.
 
B

Bob

Thanks

Göran Andersson said:
That means that the querystring value can not be converted to an integer.
This has nothing to do with how you call the stored procedure, as the code
never gets that far.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top