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
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