problem with sending and returning value in/from stored proc

Discussion in 'ASP .Net' started by Bob, Nov 10, 2007.

  1. Bob

    Bob Guest

    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
     
    Bob, Nov 10, 2007
    #1
    1. Advertising

  2. 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
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Nov 10, 2007
    #2
    1. Advertising

  3. Bob

    Bob Guest

    Thanks

    "Göran Andersson" <> schreef in bericht
    news:...
    > 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
     
    Bob, Nov 10, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiggaz
    Replies:
    2
    Views:
    2,223
    Todd Casey
    Jul 8, 2004
  2. David Lozzi

    Returning a value from a stored proc

    David Lozzi, Aug 10, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    596
    Edd Connolly
    Aug 11, 2004
  3. hansiman
    Replies:
    0
    Views:
    497
    hansiman
    Feb 5, 2005
  4. David Lozzi
    Replies:
    3
    Views:
    1,941
    David Lozzi
    Jun 1, 2005
  5. bogdan
    Replies:
    3
    Views:
    563
    bruce barker
    Apr 8, 2008
Loading...

Share This Page