Click to See Complete Forum and Search --> : Executing SQL Server stored procedure from vb6


mallli_
11-18-2004, 01:33 AM
Hi all,

Can anyone help me provide the code as to how to Execute a SQL Server stored procedure with a parameter from vb6.

Thanks

Phil Weber
11-18-2004, 03:14 AM
http://www.freevbcode.com/ShowCode.Asp?ID=3687

mallli_
11-18-2004, 03:26 AM
Hi Weber,

Thanks for your reply. Actually I need to pass a parameter to the stored procedure. For example, in sql server the stored procedure is executed as exec test '200410' .

I have been trying this code
Private Sub Form_Load()
Dim con As New ADODB.Connection
Dim stmt, parm As String
Dim rs As New ADODB.Recordset
con.ConnectionTimeout = 100


con.Open "northwind", "userid", "password"

parm = "200410"

stmt = " test '" & parm & "'"
rs.Open stmt, con, adOpenStatic, adLockReadOnly, adCmdStoredProc
If rs.STATE = adStateOpen Then rs.Close
If con.STATE = adStateOpen Then con.Close
Set rs = Nothing
Set con = Nothing


End Sub


It throws an error [Microsoft][ODBC Sql Server Driver] Syntax error or access violation.

Please help as to where the statement is failing.

Thnks & Rgds,
Mallik

pclement
11-18-2004, 09:50 AM
See if the following helps:

Calling a Stored Procedure with a Command (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdconcommandstoredproc.asp)