Error using sql command Insert (SQL Server), via classic ASP

0

Good evening, I'm having a problem executing a sql command through an ASP application.

The command is this:

strSql =    " INSERT INTO movimento_tef_nsu (           "&_
            "   identificador                           "&_
            "   ,nsu_sitef                              "&_
            "   ,valor                                  "&_
            "   ,ordem_cartao                           "&_
            "   ,data_hora                              "&_
            "   ,texto_comprovante                      "&_
            "   )                                       "&_
            " VALUES (                                  "&_
            "   '" & objJSON.data("identificador") & "' "&_
            "   ," & this.item("nsu")                   &_
            "   ," & this.item("valor")                 &_
            "   ," & this.item("ordem_cartao")          &_
            "   ,'" & this.item("data_hora") & "' "     &_           
            "   ,LEFT('" & this.item("texto_comprovante") & "', 255) "&_
            "   )                                       "

I have already checked that the values (which are coming via JSON), are correct, as I write to a Log before executing the command.

The error that occurs is as follows:

  

"An unspecified error occurred! Microsoft OLE DB Provider for SQL Server, error '80040e14' Syntax error or access violation"

I also checked that the values are coming according to the type and size of the fields in the database, so if I get the query that is in the log and run in sql management, it works normally.

Does anyone have a suggestion of what this error might be?

    
asked by anonymous 25.07.2014 / 14:07

1 answer

0

The problem is here

",LEFT('" & this.item("texto_comprovante") & "', 255) "

The comma of left causes mySQL to understand that there is one more parameter to solve, use the function before calling the query, save it to a variable and use it in INSERT.

 textoComprovante = LEFT('" & this.item("texto_comprovante") & "', 255)

strSql = " INSERT INTO movimento_tef_nsu 
   (identificador, nsu_sitef, valor, ordem_cartao,data_hora, texto_comprovante) 
    VALUES
    ('" & objJSON.data("identificador") & "', " & this.item("nsu") & ", " & this.item("valor")
    &", " & this.item("ordem_cartao") &", '" & this.item("data_hora") & "', '" & textoComprovante & "'")
07.08.2014 / 15:57