How do you call a Stored Procedure from a SQL 7.0 Database from Visual Basic?
Printable View
How do you call a Stored Procedure from a SQL 7.0 Database from Visual Basic?
Code:dim moADODB as new ADODB.Connection
dim mrsData as new ADODB.Recordset
moADODB.Open msconnection
mrsData.Open "exec sp_Collect " & lsParams, moADODB.Connection, adOpenStatic
would do the trick
AngelaMicikas, hope this can help you.
Code:Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Set conn = New ADODB.Connection
conn.Open "Provider=SQLOLEDB;Data Source=Chris;Database=pubs;User Id=sa;password=;"
Set cmd = New ADODB.Command
cmd.CommandText = "<Your Store Procedure Name>"
cmd.CommandType = adCmdStoredProc
Set cmd.ActiveConnection = conn
Set rs = cmd.Execute
With rs
'Do what ever you want here
End With
Set cmd = Nothing
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
This should do it...
Dim objConn as ADODB.Connection
Dim objCmd as ADODB.Command
Dim objRs as ADODB.Recordset
<Set and open connection object>
Set objCmd = New ADODB.Command
objCmd.CommandType = adCmdStoredProc
objCmd.CommandText = " <StoredProcName>"
objCmd.ActiveConnection = objConn
Set objRs = objCmd.Execute
If the Stored Procedure does not return a recordset, then the last line would be:
objCmd.execute lRecReturned
Where lRecReturned = number of records affected by executing the Stored Procedure...
THANKS.