0

我有一个设计,如下所述,需要一个接一个地执行(可能)多个存储过程。

   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,因为我们仍然在现场部署了这两个版本。

4

1 回答 1

1

你看到了吗?
4 是 的值adCmdStoredProc。你用那个覆盖.CommandText。使用.CommandType而不是第二个.CommandText.

于 2012-11-03T20:32:36.540 回答