Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > problem with sending and returning value in/from stored proc

Reply
Thread Tools

problem with sending and returning value in/from stored proc

 
 
Bob
Guest
Posts: n/a
 
      11-10-2007
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      11-10-2007
Bob wrote:
> 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.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
 
 
 
Bob
Guest
Posts: n/a
 
      11-10-2007
Thanks

"Göran Andersson" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Bob wrote:
>> 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.
>
> --
> Göran Andersson
> _____
> http://www.guffa.com



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TableAdapter returns null for stored proc returning a single value bogdan ASP .Net 3 04-08-2008 03:10 PM
Convert VB.NET to TSQL PROC & Reference a Proc from another Proc David Lozzi ASP .Net 3 06-01-2005 06:35 PM
Returning a value from a stored proc David Lozzi ASP .Net 6 08-11-2004 09:13 PM
How to get the returned value from Stored Proc. ? Jiggaz ASP .Net 2 07-08-2004 08:44 PM
What is the diff btwn 'sho proc' and 'sho proc cpu' William J King Cisco 1 12-18-2003 11:50 PM



Advertisments