1

I am trying to execute an UPDATE SQL query using an ADODB.Command object. I never used it before so I may be doing stupid mistakes, her's a copy of my code:

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

My error trigger on .Execute it says [MySQL][ODBC 5.3(a) Driver][mysqld-5.5.16]Invalid parameter type. Is adLongVarChar not the right type to use for a string value ?

EDIT : After trying @h2so4 's method (concatenating the parameter values into the command string), I get an other error saying

[MySQL][ODBC 5.3(a) Driver][mysqld-5.5.16]our le champ 'this MySQL version'.

No idea what it means but it triggers on my executing line :

connect.Execute sqlQuery, , adCmdText

2 Answers 2

0

In the end, my error was that the table name offres was not right it was offre.

Sign up to request clarification or add additional context in comments.

Comments

-1

to my opinion you could adapt your sql like this and get rid of the parameters.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 & "';"

6 Comments

That was my first try, but I was advised to use the adodb.Command instead : stackoverflow.com/questions/43521839/… . The question is not the same but the query is
@NattyRoots you should give this a try at least to make sure that the problem is in the way you use the ADODB.Command and not in the query itself, or in the parameter values...
@A.S.H I went through every parameters value in debug mode and they were fine. I'll try it out anyway just in case
@A.S.H Tried it : it gets me a new error, I'll edit it in the question
The query still needs some tweaking. i.e. use '...' only for varchar fields not numeric fields, enclose dates with #...# instead of '...' etc. @NattyRoots
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.