Stored Procedure Return Values

Discussion in 'ASP .Net' started by Adam Knight, Dec 14, 2005.

  1. Adam Knight

    Adam Knight Guest

    Hi all,

    I am wanting to get a stored procedure return value via ADO.NET..

    Code: Below:
     
    Adam Knight, Dec 14, 2005
    #1
    1. Advertising

  2. Adam Knight

    Adam Knight Guest

    Stupid computer!!!

    'sp to insert
    cmdInsertContractor = New SqlCommand("ins_cntr_mgt_contractor", Conn)
    cmdInsertContractor.CommandType = CommandType.StoredProcedure
    cmdInsertContractor.Parameters.Add(New SqlParameter("@mid",
    Trim(Session("MID"))))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@company",
    Trim(txtCompany.Text)))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@first_name",
    Trim(txtFirstName.Text)))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@last_name",
    Trim(txtLastName.Text)))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@email",
    Trim(txtEmail.Text)))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@mobile",
    Trim(txtMobile.Text)))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@phone",
    Trim(txtPhone.Text)))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@position",
    Trim(txtPositionHeld.Text)))
    cmdInsertContractor.Parameters.Add(New SqlParameter("@ctype",
    Trim(rbtnContractorType.SelectedValue)))

    What do i need to add to create a return value parameter?

    Cheers,
    Adam
     
    Adam Knight, Dec 14, 2005
    #2
    1. Advertising

  3. Adam,

    try adding the following code:

    Dim returnValue as SqlParameter = New SqlParameter()
    returnValue.Direction = ParameterDirection.ReturnValue
    cmdInsertContractor.Parameters.Add(returnValue)
    ' Execute sp here
    ' After execution, you can read the returncode from returnValue
    Console.WriteLine(string.Format("ReturnValue: {0}", returnValue.Value))

    check out
    http://msdn.microsoft.com/library/d...ml/cpconinputoutputparametersreturnvalues.asp (watch line-wraps) for more info...

    HTH,
    Baileys

    "Adam Knight" wrote:

    > Stupid computer!!!
    >
    > 'sp to insert
    > cmdInsertContractor = New SqlCommand("ins_cntr_mgt_contractor", Conn)
    > cmdInsertContractor.CommandType = CommandType.StoredProcedure
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@mid",
    > Trim(Session("MID"))))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@company",
    > Trim(txtCompany.Text)))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@first_name",
    > Trim(txtFirstName.Text)))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@last_name",
    > Trim(txtLastName.Text)))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@email",
    > Trim(txtEmail.Text)))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@mobile",
    > Trim(txtMobile.Text)))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@phone",
    > Trim(txtPhone.Text)))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@position",
    > Trim(txtPositionHeld.Text)))
    > cmdInsertContractor.Parameters.Add(New SqlParameter("@ctype",
    > Trim(rbtnContractorType.SelectedValue)))
    >
    > What do i need to add to create a return value parameter?
    >
    > Cheers,
    > Adam
    >
    >
    >
     
    =?Utf-8?B?QmFpbGV5cw==?=, Dec 14, 2005
    #3
  4. Adam there are more samples here at:-
    http://www.developerfusion.co.uk/show/4278/3/
    Patrick

    "Baileys" <> wrote in message
    news:...
    > Adam,
    >
    > try adding the following code:
    >
    > Dim returnValue as SqlParameter = New SqlParameter()
    > returnValue.Direction = ParameterDirection.ReturnValue
    > cmdInsertContractor.Parameters.Add(returnValue)
    > ' Execute sp here
    > ' After execution, you can read the returncode from returnValue
    > Console.WriteLine(string.Format("ReturnValue: {0}", returnValue.Value))
    >
    > check out
    >

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
    l/cpconinputoutputparametersreturnvalues.asp (watch line-wraps) for more
    info...
    >
    > HTH,
    > Baileys
    >
    > "Adam Knight" wrote:
    >
    > > Stupid computer!!!
    > >
    > > 'sp to insert
    > > cmdInsertContractor = New SqlCommand("ins_cntr_mgt_contractor", Conn)
    > > cmdInsertContractor.CommandType = CommandType.StoredProcedure
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@mid",
    > > Trim(Session("MID"))))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@company",
    > > Trim(txtCompany.Text)))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@first_name",
    > > Trim(txtFirstName.Text)))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@last_name",
    > > Trim(txtLastName.Text)))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@email",
    > > Trim(txtEmail.Text)))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@mobile",
    > > Trim(txtMobile.Text)))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@phone",
    > > Trim(txtPhone.Text)))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@position",
    > > Trim(txtPositionHeld.Text)))
    > > cmdInsertContractor.Parameters.Add(New SqlParameter("@ctype",
    > > Trim(rbtnContractorType.SelectedValue)))
    > >
    > > What do i need to add to create a return value parameter?
    > >
    > > Cheers,
    > > Adam
    > >
    > >
    > >
     
    Patrick.O.Ige, Dec 14, 2005
    #4
    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. Neo Chou
    Replies:
    1
    Views:
    799
  2. Paul
    Replies:
    1
    Views:
    395
    =?Utf-8?B?UmFtaXJvIENhbGRlcm9u?=
    Jan 19, 2004
  3. Scott Natwick
    Replies:
    2
    Views:
    6,673
    Scott Natwick
    Oct 3, 2004
  4. =?Utf-8?B?bmVpbF9wYXQ=?=

    Redirect based on stored procedure return values

    =?Utf-8?B?bmVpbF9wYXQ=?=, Mar 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,967
  5. Mike P
    Replies:
    0
    Views:
    3,385
    Mike P
    Jun 19, 2006
Loading...

Share This Page