我試着用MS-Access 2007中一個簡單的參數化的插入,我不斷從ADODB.Parameters
收到以下錯誤(3708):VBA/MS-ACCESS中帶有備註和文本字段的參數化INSERT?
Parameter object is improperly defined. Inconsistent or incomplete information was provided. s'
我有插入到了3場3個參數。它們有以下幾種類型:
- QUERY_NAME:TEXT(50)
- DB_ID:數字(長整型)
- QUERY_TEXT:備註
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
的following reference說,數據庫類型的字段MEMO
S的關係有adLongVarChar
參數類型和類型的數據庫類型TEXT
,應該有一個類型的adVarChar
。
您嘗試過'adLongVarWChar'和'adVarWChar'嗎? –
我嘗試了兩種方法,假設'LongVarWChar'用於備註字段,'adVarWChar'用於文本字段,這不起作用。 – leeand00