Skip to content Skip to sidebar Skip to footer

Update Sql Command Syntax Error

I've checked and rechecked and looked over and over at it but can't understand what's wrong with it. I have this code to make the insert that works fine: cmd.Parameters.Add(new Ole

Solution 1:

The syntax of the update goes roughly as follows:

UPDATE<table name>SET<list ofcolumn expressions>WHERE<condition>

Note that there are no parentheses around the list of the column expressions.

So you should rewrite your UPDATE like this:

cmd.CommandText = "UPDATE [Movimento Ferramentas] SET " + // <<== Changed the order
            "Codigo = @codigo, " +                        // <<== Removed (
            "[Data saida] = @data, " +
            "[Entidade] = @entidade, " +
            "[Data Ent] = null, " +
            "[GT EntT Nº] = null," +
            "Estado = 'Calibração', " +
            "[GT Saida Nº] = null, " +
            "[Observações1] = @observacao," +
            "Requesitante = null," +
            "Certificado = @certificado, " +
            "Resultado = @resultado, " +
            "Seleccionar = @selecionar," +
            "[Tipo de Intervenção] = null " +             // <<== Removed )
            "WHERE Certificado = @certificadoAnterior";

Solution 2:

Instead of

UPDATESET [Movimento Ferramentas] "

do

UPDATE [Movimento Ferramentas] SET "

Solution 3:

this is wrong update statement...Correct statement is below..

cmd.CommandText = "UPDATE [Movimento Ferramentas] SET " +
              "Codigo = @codigo, " +
            "[Data saida] = @data, " +
            "[Entidade] = @entidade, " +
            "[Data Ent] = null, " +
            "[GT EntT Nº] = null," +
            "Estado = 'Calibração', " +
            "[GT Saida Nº] = null, " +
            "[Observações1] = @observacao," +
            "Requesitante = null," +
            "Certificado = @certificado, " +
            "Resultado = @resultado, " +
            "Seleccionar = @selecionar," +
            "[Tipo de Intervenção] = null " +
            "WHERE Certificado = @certificadoAnterior";

Solution 4:

Your UPDATE syntax is wrong.

UPDATE 
    [ TOP ( expression ) [ PERCENT ] ] 
    { { table_alias | <object> | rowset_function_limited 
         [ WITH ( <Table_Hint_Limited> [ ...n ] ) ]
      }
      | @table_variable    
    }

Table names should be on between UPDATE and SET parts.

Change your;

UPDATESET [Movimento Ferramentas]

to

UPDATE [Movimento Ferramentas] SET

Full command should be like;

cmd.CommandText = "UPDATE SET [Movimento Ferramentas] 
                  (Codigo = @codigo, 
                  [Data saida] = @data, 
                  [Entidade] = @entidade, 
                  [Data Ent] = null, 
                  [GT EntT Nº] = null,
                  Estado = 'Calibração', 
                  [GT Saida Nº] = null, 
                  [Observações1] = @observacao,
                  Requesitante = null,
                  Certificado = @certificado,
                  Resultado = @resultado, 
                  Seleccionar = @selecionar,
                  [Tipo de Intervenção] = null) 
                  WHERE Certificado = @certificadoAnterior";

Post a Comment for "Update Sql Command Syntax Error"