我正在尝试使用ADODB.Command对象执行UPDATE SQL查询。我之前从未使用它,所以我可能会犯愚蠢的错误,她是我的代码的副本:
Public Function setOffre(idO As Integer, idS As Integer, ref As String, dateO As Date, dateF As Date, nomR As String, idEntRecr As Integer, emploi As String, idEtat As Integer, lieu As String, plage As String, College As String)
Dim sqlQuery As String
Dim rs As ADODB.Recordset
Set connect = New ADODB.Connection
connect.Open connString
sqlQuery = "UPDATE offres " & _
"SET source_ID = @idSource, " & _
"reference = @idRef, " & _
"recruteur = @recruteur, " & _
"lieu = @lieu, " & _
"etat_ID = @idEtat, " & _
"emploi = @emploi, " & _
"plage = @plage, " & _
"college = @college, " & _
"offre_Date = @dateO, " & _
"offre_Forclusion = @forcO, " & _
"offre_Mois = @moisO, " & _
"entite_ID = @idEntite " & _
"WHERE offre_ID = @idOffre;"
With New ADODB.Command
.ActiveConnection = connect
.CommandType = adCmdText
.NamedParameters = True
.CommandText = sqlQuery
.Parameters.Append .CreateParameter("@idSource", adInteger, adParamInput, 10, idS)
.Parameters.Append .CreateParameter("@idRef", adLongVarChar, adParamInput, 10, ref)
.Parameters.Append .CreateParameter("@recruteur", adLongVarChar, adParamInput, 100, nomR)
.Parameters.Append .CreateParameter("@lieu", adLongVarChar, adParamInput, 100, lieu)
.Parameters.Append .CreateParameter("@idEtat", adInteger, adParamInput, 10, idEtat)
.Parameters.Append .CreateParameter("@emploi", adLongVarChar, adParamInput, 200, emploi)
.Parameters.Append .CreateParameter("@plage", adLongVarChar, adParamInput, 10, plage)
.Parameters.Append .CreateParameter("@college", adLongVarChar, adParamInput, 200, College)
.Parameters.Append .CreateParameter("@dateO", adDate, adParamInput, 10, Format(dateO, "yyyy-mm-dd"))
.Parameters.Append .CreateParameter("@forcO", adDate, adParamInput, 10, Format(dateF, "yyyy-mm-dd"))
.Parameters.Append .CreateParameter("@moisO", adInteger, adParamInput, 10, Month(dateO))
.Parameters.Append .CreateParameter("@idEntite", adInteger, adParamInput, 10, idEntRecr)
.Parameters.Append .CreateParameter("@idOffre", adInteger, adParamInput, 10, idO)
.Execute
End With
connect.Close
End Function
.Execute
上的{}错误触发[MySQL][ODBC 5.3(a) Driver][mysqld-5.5.16]Invalid parameter type
。 adLongVarChar
不是用于字符串值的正确类型吗?
编辑: 在尝试了@ h2so4的方法(将参数值连接到命令字符串中)之后,我收到了另一个错误
[MySQL][ODBC 5.3(a) Driver][mysqld-5.5.16]our le champ 'this MySQL version'
。
不知道它意味着什么,但它在我的执行线上触发:
connect.Execute sqlQuery, , adCmdText
答案 0 :(得分:1)
我认为你可以像这样修改你的sql并摆脱参数.append
sqlQuery = "UPDATE offres " & _
"SET source_ID = '" & idS & "', " & _
"reference = '" & ref & "', " & _
"recruteur = '" & nomR & "', " & _
"lieu = '" & lieu & "', " & _
"etat_ID = '" & idEtat & "', " & _
"emploi = '" & emploi & "', " & _
"plage = '" & plage & "', " & _
"college = '" & college & "', " & _
"offre_Date = '" & Format(dateO, "yyyy-mm-dd") & "', " & _
"offre_Forclusion = '" & Format(dateO, "yyyy-mm-dd") & "', " & _
"offre_Mois ='" & Month(dateO) & "', " & _
"entite_ID = '" & identRecr & "'" & _
"WHERE offre_ID = '" & ido & "';"
答案 1 :(得分:0)
最后,我的错误是表名offre
不对,它是Hotel1, Hotel2, Hotel3
。