troubleshooting Question

SQL Server output in code behind

Avatar of Larry Brister
Larry BristerFlag for United States of America asked on
.NET ProgrammingMicrosoft SQL Server 2005
1 Comment1 Solution193 ViewsLast Modified:
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),
 @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.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)
        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()
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros