我正在尝试使用 MS-Access 2007 进行简单的参数化插入,但我不断收到以下错误 (3708) ADODB.Parameters
:
Parameter object is improperly defined. Inconsistent or incomplete information was provided.
s'
我有 3 个参数被插入到 3 个字段中。它们有以下几种:
- 查询名称:文本(50)
- db_id:数字(长整数)
- 查询文本:备忘录
db_id
插入就好了,但其他两个文本字段会导致上述错误。
下面是我的简单示例代码:
Sub testz()
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
Dim adoCMD As ADODB.Command
Dim adoRS As ADODB.Recordset
Dim strSQL As String
Dim lRecordsAffected As Long
On Error GoTo Err_Insert
strSQL = "INSERT INTO queries (query_name, db_id, query_text) VALUES (?, ?, ?)"
Set adoCMD = New ADODB.Command
With adoCMD
Dim test As String
test = "tetws"
.ActiveConnection = conn
.CommandType = adCmdText
.CommandText = strSQL
.Parameters.Append .CreateParameter("x1", adVarChar, adParamInput) ' Doesn't work - MS ACCESS Text field
.Parameters.Append .CreateParameter("x2", adInteger, adParamInput) ' This works - Numeric field
.Parameters.Append .CreateParameter("x3", adLongVarChar, adParamInput) ' This doesn't work MS ACCESS Memo field.
.Parameters("x1").Value = test
.Parameters("x2").Value = 56
.Parameters("x3").Value = test
adoCMD.Execute adExecuteNoRecords
End With
If lRecordsAffected = 0 Then
Debug.Print ("------------------------")
Debug.Print ("ERROR QUERY not inserted:")
Debug.Print ("database id: " & id)
Debug.Print ("query name: " & tblName)
Debug.Print ("strSQL: " & qryTxt)
Debug.Print ("------------------------")
Else
End If
Exit_Insert:
Set adoCMD = Nothing
Set adoRS = Nothing
Exit Sub
Err_Insert:
Debug.Print "----------------"
Debug.Print "BEGIN: Err"
If err.Number <> 0 Then
Msg = "Error # " & Str(err.Number) & " was generated by " _
& err.Source & Chr(13) & "Error Line: " & Erl & Chr(13) & err.Description
'MsgBox Msg, , "Error", err.HelpFile, err.HelpContext
Debug.Print Msg
End If
Resume Exit_Insert
End Sub
以下参考资料说数据库类型MEMO
s 的字段应该有一个参数类型,adLongVarChar
并且该类型数据库类型TEXT
应该有一个类型adVarChar
。