Click to See Complete Forum and Search --> : Running Stored Procedure


Ehsan
April 30th, 2001, 04:45 AM
Hello

I want to know how can I run a sql server stored procedure from my program written in VB

Thannks
Ehsan

TimCottee
April 30th, 2001, 08:00 AM
Dim cnn as ADODB.Connection
Dim rst as ADODB.Recordset
set cnn = new ADODB.Connection
set rst = new ADODB.Recordset
cnn.ConnectionString = "Your Connection string"
cnn.Open
'for a stored procedure which doesn't return any records
cnn.Execute "sp_MyStoredProcedure 'Param1',2"
'to return records use either:
set rst = cnn.Execute ("sp_MyStoredProcedure 'Param1',2)
'Or
rst.Open "Execute sp_MyStoredProcedure 'Param1',2",cnn,adOpenStatic,adLockOptimistic
rst.Close
set rst = nothing
cnn.Close
set cnn = nothing