0

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 OleDbParameter("@codigo", cal.CodEtiq.ToString()));
cmd.Parameters.Add(new OleDbParameter("@data", cal.Data));
cmd.Parameters.Add(new OleDbParameter("@entidade", cal.EntidadeCal));
cmd.Parameters.Add(new OleDbParameter("@observacao", cal.Observacao));
cmd.Parameters.Add(new OleDbParameter("@certificado", cal.Certificado));
cmd.Parameters.Add(new OleDbParameter("@resultado", cal.Resultado));
cmd.Parameters.Add(new OleDbParameter("@selecionar", cal.Selecionar));
cmd.Parameters.Add(new OleDbParameter("@null", DBNull.Value));

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

And now I have this code for the update that keeps giving me Invalid Arguments error.

cmd.Parameters.Add(new OleDbParameter("@codigo", cal.CodEtiq.ToString()));
cmd.Parameters.Add(new OleDbParameter("@data", cal.Data));
cmd.Parameters.Add(new OleDbParameter("@entidade", cal.EntidadeCal));
cmd.Parameters.Add(new OleDbParameter("@observacao", cal.Observacao));
cmd.Parameters.Add(new OleDbParameter("@certificado", cal.Certificado));
cmd.Parameters.Add(new OleDbParameter("@resultado", cal.Resultado));
cmd.Parameters.Add(new OleDbParameter("@selecionar", cal.Selecionar));
cmd.Parameters.Add(new OleDbParameter("@certificadoAnterior", certificadoAnterior));

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";

So what is wrong with the update?

EDIT: As requested it'd be something like the following I think

String myCommand = "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";
4
  • Could you do like String myCommand = "your sql statement"; Be easier to look at if we can see what it's outputting Commented Nov 4, 2013 at 12:15
  • I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not". Commented Nov 4, 2013 at 12:17
  • Your edit is still incorrect, the table name needs to be between UPDATE and SET, i.e. UPDATE [Movimento Ferramentas] SET Commented Nov 4, 2013 at 12:25
  • @christiandev The edit was for Sythnet comment before I got any of the answers. Either way, it's working now, thanks. Commented Nov 4, 2013 at 12:29

4 Answers 4

2

The syntax of the update goes roughly as follows:

UPDATE <table name>
SET <list of column 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";
Sign up to request clarification or add additional context in comments.

1 Comment

Good catch on the parentheses
2

Instead of

UPDATE SET [Movimento Ferramentas] "

do

UPDATE [Movimento Ferramentas] SET "

Comments

2

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";

Comments

1

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;

UPDATE SET [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";

Comments

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.