W
Woody Splawn
I am using SQL Server 2000 as the back-end. I have created a stored
procedure in SQL server called usp_AddContract. This Stored procedure
inserts a new contract into a contracts table. I have tested the code in
Enterprise Manager and it works correctly. At the time that I run the SP I
pass a contract number and a SSN to the SP and it creates a new contract in
the contracts table with a unique value in the ConNum field and SSN field.
In order to run the stored procedure from within SQL Server, in Query
Analizer I do the following:
DECLARE @retCode int
DECLARE @ConNum nvarchar(10)
DECLARE @SSN nvarchar(11)
SET @ConNum = 'T00003'
SET @SSN = '554319132'
EXECUTE @retCode = usp_AddContract @ConNum,@SSN
PRINT @retCode
My question is, how do I do call the stored procedure under code in Visual
Studio. If I had a button on a form, what code would I write to call and
execute the stored procedure above?
I have fiddled with it myself and tried the following code in a button but I
seem to be missing something with regard to how to actually execute the SP.
(mySQLConnection and myConnectionString are public variables declared
elsewhere in my form)
Dim cmdContracts As New SqlCommand
mySqlConnection = New SqlConnection(myConnectionString)
mySqlConnection.Open()
cmdContracts = mySqlConnection.CreateCommand
cmdContracts.CommandType = CommandType.StoredProcedure
cmdContracts.CommandText = "usp_AddContract"
cmdContracts.Parameters.Add(New SqlParameter("@ConNum", "T00005"))
cmdContracts.Parameters.Add(New SqlParameter("@SSN", "554319132"))
mySqlConnection.Close()
Thank You
procedure in SQL server called usp_AddContract. This Stored procedure
inserts a new contract into a contracts table. I have tested the code in
Enterprise Manager and it works correctly. At the time that I run the SP I
pass a contract number and a SSN to the SP and it creates a new contract in
the contracts table with a unique value in the ConNum field and SSN field.
In order to run the stored procedure from within SQL Server, in Query
Analizer I do the following:
DECLARE @retCode int
DECLARE @ConNum nvarchar(10)
DECLARE @SSN nvarchar(11)
SET @ConNum = 'T00003'
SET @SSN = '554319132'
EXECUTE @retCode = usp_AddContract @ConNum,@SSN
PRINT @retCode
My question is, how do I do call the stored procedure under code in Visual
Studio. If I had a button on a form, what code would I write to call and
execute the stored procedure above?
I have fiddled with it myself and tried the following code in a button but I
seem to be missing something with regard to how to actually execute the SP.
(mySQLConnection and myConnectionString are public variables declared
elsewhere in my form)
Dim cmdContracts As New SqlCommand
mySqlConnection = New SqlConnection(myConnectionString)
mySqlConnection.Open()
cmdContracts = mySqlConnection.CreateCommand
cmdContracts.CommandType = CommandType.StoredProcedure
cmdContracts.CommandText = "usp_AddContract"
cmdContracts.Parameters.Add(New SqlParameter("@ConNum", "T00005"))
cmdContracts.Parameters.Add(New SqlParameter("@SSN", "554319132"))
mySqlConnection.Close()
Thank You