我有一个设计,如下所述,需要一个接一个地执行(可能)多个存储过程。
Dim cn As ADODB.Connection: Set cn = New ADODB.Connection
Dim srv As String: srv = GetValue("tblBrandDatabase", abbr)
Dim db As String: db = GetValue("tblBrandDatabase", abbr, 3)
Dim connstr As String
connstr = "Provider=SQLNCLI10;Server=" & srv & _
";Database=" & db & _
";Trusted_Connection=yes"
cn.Open connstr
ProcessEmplData wb, cn
If (cn.State = adStateOpen) Then cn.Close
cn.Open connstr
Dim cmd As ADODB.Command: Set cmd = New ADODB.Command
With cmd
Set .ActiveConnection = cn
'Process the new Imported Employee Data
.CommandText = "Process_EmplData"
.CommandText = adCmdStoredProc
.Execute
End With
If (cn.State = adStateOpen) Then cn.Close
Set cn = Nothing
如何在不收到错误代码Run-time error -2147217900 (80040e14) - Incorrect syntax near '4'
的情况下取得成功?
需要适用于2007/2010,因为我们仍然在现场部署了这两个版本。
答案 0 :(得分:1)
你看到了吗?
4是adCmdStoredProc
的值。你用它覆盖.CommandText
。使用.CommandType
代替第二个.CommandText
。