
Stored procedure error using ADO/ODBC connection - help?
Hello Vic,
when using ADO and stored procedures with parameters, you want to use the
ADO command object. Please see the MSDN ADO reference for details. Here's
how you could modify your code:
Dim cn As ADODB.Connection
Dim co As ADODB.Command
Dim params(3) As ADODB.Parameter
Dim s As String
Set cn = New ADODB.Connection
Set co = New ADODB.Command
cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=Address"
Set co.ActiveConnection = cn
Set params(0) = co.CreateParameter("CustomerID", adInteger,
adParamInput, , 1)
co.Parameters.Append params(0)
Set params(1) = co.CreateParameter("CustomerName", adChar, adParamInput,
10, "Peter Miller")
co.Parameters.Append params(1)
Set params(2) = co.CreateParameter("AreaCode", adChar, adParamInput, 10,
Null)
co.Parameters.Append params(2)
co.CommandText = "UpdateCustomer"
co.CommandType = adCmdStoredProc
co.Execute
cn.Close
This would call the following SP:
CREATE PROCEDURE UpdateCustomer
AS
SET NOCOUNT ON
The ADO command object provides better capabilities to call stored
procedures with both input and output parameters. It requires a bit more
coding, though.
Regards,
Uwe Baumann
Quote:
> Hi -
> I'm new to ADO/VB and have had great success getting data _out_ of my
> database, but I'm now trying to put it back in via stored procs and am
> getting
> syntax errors I can't seem to debug. The code snippet I am calling is
this:
> Dim sAC As String
> If (bEditMode = True) Then
> bEditMode = False
> If txtAreaCode.Text = "" Then
> sAC = "NULL"
> Else
> sAC = txtAreaCode.Text
> End If
> strSQL = "SP_UpdateCustomer " & lblCustID.Caption & ", '" &
> txtCoName.Text & "'," & sAC
> cn.Execute strSQL, , adCmdStoredProc
> The strSQL reads as: SP_UpdateCustomer 1, 'Boeing North America,
> Inc.aaaaasdfsdf',NULL
> This command _works fine_ when I execute it in ISQL/w but bombs when I
call
> it from my code. It also works if I only pass one parameter (company
name).
> When
> I add the second parameter, it dies! Any information very much
appreciated.
> I don't
> have much hair left! TIA -
> Vic Bachulis
> DatabaseDesigners.com (sm)
> remove the "nospam_" to reply, please.