473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with sending and returning value in/from stored proc

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
Nov 10 '07 #1
2 877
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
Nov 10 '07 #2
Bob
Thanks

"Göran Andersson" <gu***@guffa.comschreef in bericht
news:eM*************@TK2MSFTNGP03.phx.gbl...
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

Nov 10 '07 #3

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

Similar topics

2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
6
by: David Lozzi | last post by:
Here is the proc: CREATE PROCEDURE . @CID as int, @Netname as nvarchar(25), @Return as int OUTPUT AS IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND...
7
by: Peter D.C. | last post by:
Hi I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL...
2
by: Pavel Stehule | last post by:
Hello I need use ADODB client via ODBC. I can call stored proc without problems. I am sure so proc is called (I am loging params) but retern value is always null. dim cn as new...
2
by: jzogg7272 | last post by:
In my code I am executing a stored procedure to do a single row insert. I check the return value of the execution and I am getting -1, whereas a few weeks ago it was returning 0. Actually, I found...
3
by: JJ | last post by:
When running an sql stored procedure, is it possible to pass in the sortexpression as a parameter? When I try it all the other parameters operate as expected, but the rows are not sorted. The...
2
by: Bob | last post by:
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...
8
by: Tom P. | last post by:
I have a webpage that takes user data and sends it to a stored procedure that inserts a row in a table then returns the ID of that row for display. The stored procedure does an insert then it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.