Avatar of Larry Brister
Larry BristerFlag for United States of America asked on

SQL Server output in code behind

I have a SQL Server Stored procedure that has variables that need to be passed in BUT also there an out variable I have to allow for in my code behind...  how do I allow for that in my VB>

SQL Server Code and VB Code
ALTER PROCEDURE [dbo].[InsertHotel]
 -- Add the parameters for the stored procedure here
 -- Resorts
 @Name    varchar(200),
 @Address1   varchar(100),
 @Address2   varchar(100),
blah...blah..blah...
 @HotelID   int output

VB Code behind...

Public Sub insertHotel()

        Dim C As New clsDBConnectivity

        C.dbCmnd.CommandText = "insertHotel"
        C.dbCmnd.CommandType = System.Data.CommandType.StoredProcedure
        C.dbCmnd.Parameters.Clear()
        C.dbCmnd.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.Int)).Value = Session("custID")
        C.dbCmnd.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Address1", System.Data.SqlDbType.Int)).Value = cmbFirm.SelectedValue
        C.dbCmnd.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Address2", System.Data.SqlDbType.NVarChar, 50)).Value = cmbStatus.SelectedValue
        C.dbCmnd.Parameters.Add(New System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 50)).Value = Trim(txtContract.Text)
       blah...blah...blah...
        C.dbCmnd.Parameters.Add(New System.Data.SqlClient.SqlParameter("@fndOtherFee", System.Data.SqlDbType.Money)).Value = 0
        C.dbCmnd.Parameters.Add(New System.Data.SqlClient.SqlParameter("@fnDCalcTotal", System.Data.SqlDbType.Money)).Value = ttlAmount.Text
        C.dbCmnd.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UserID", System.Data.SqlDbType.Int)).Value = Session("UserID")

        Dim dr = C.dbCmnd.ExecuteReader()
        dr.Read()
.NET ProgrammingMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
Joel Coehoorn

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Joel Coehoorn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61