2

Sorry if this isn't the place to post this, but I don't know anywhere else to find help. The insert command won't work, might be something dumb but I can't find what's causing the problem, it says that it's a syntax error.

The code:

conn.Open();
            OleDbCommand cmd = new OleDbCommand("Insert into Partes(User, Título, Fecha, Link, CODEMP, CODFOR, NROFOR) " +
                "Values (@user, @titulo, @fecha, @link, @codemp, @codfor, @nrofor)", conn);
            cmd.Parameters.AddWithValue("user", Convert.ToString(Session["User"]));
            cmd.Parameters.AddWithValue("titulo", title.Text);
            cmd.Parameters.AddWithValue("fecha", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
            cmd.Parameters.AddWithValue("link", link.Text);
            cmd.Parameters.AddWithValue("codemp", codemp.Text);
            cmd.Parameters.AddWithValue("codfor", codfor.Text);
            cmd.Parameters.AddWithValue("nrofor", nrofor.Text);
            cmd.ExecuteNonQuery();
  System.Data.OleDb.OleDbException
  HResult=0x80040E14
  Mensaje = Error de sintaxis en la instrucción INSERT INTO.
  Origen = <No se puede evaluar el origen de la excepción>
  Seguimiento de la pila:
<No se puede evaluar el seguimiento de la pila de excepciones>

"Syntax error in the INSER INTO instruction." "The exception stack trace can't be evaluated."

13
  • maybe it's not "Título" but "Titulo" ? Commented Jul 22, 2019 at 13:18
  • Already tried that, but it's not the problem. The field is "Título" in the database and I have other fields as "Descripción" that work. Commented Jul 22, 2019 at 13:20
  • Try to pass a fixed value in User or in the others ("user", "randomvalue"); to see if that's the problem. Debug line by line and see where it crashes (Insert a breakpoint (F9) and while running press F10 to iterate trough); Check the constraints on sql; Commented Jul 22, 2019 at 13:29
  • Have you done inserts before with SQL-style parameters @? It should work but I don't know if it works on older versions of Access. If yours is not old, nevermind. Commented Jul 22, 2019 at 13:40
  • 1
    hmm... try to rename User column name or enclose it with square brackets like this [User] bc it's a reserved keyword for MSAccess. if not try this - (You have to add the parameters in the order you want them.) Commented Jul 22, 2019 at 14:08

0

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.