SQL CE Insert Error in Database

Asked

Viewed 210 times

0

I am creating an application for a PDA, when I try to insert data in the database I always find this error.

There was an error Parsing the query. [ Token line number = 1,Token line offset = 100,Token in error = ) ]

public static bool InsertPedido(int id, int Vim, DateTime date, int quantidade)
{ 
    SqlCeConnection conn = new SqlCeConnection("Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\\DataPedido.sdf; Password =SUPER2000PED;");

    conn.Open();
    try
    { 
        SqlCeCommand comando = new SqlCeCommand(@"INSERT INTO Pedido([IDLayout], [Vim], [Data], [Quantidade])VALUES(@IDLayout,@Vim,@Data,@Quantidade))", conn); 

        comando.Parameters.AddWithValue("@IDLatout", SqlDbType.Int).Value = id;
        comando.Parameters.AddWithValue("@Vim", SqlDbType.Int).Value = Vim;
        comando.Parameters.AddWithValue("@Data", SqlDbType.DateTime).Value = date;
        comando.Parameters.AddWithValue("@Quantidade", SqlDbType.Int).Value = quantidade;

        int row = comando.ExecuteNonQuery(); 

        return true;
    }
    catch
    {
        throw;
    }
    finally
    {
        conn.Close();
    } 
}
  • There are two parentheses being closed at the end of the query string.

  • 2

    This question is about a small typo. It is too specific.

  • Funny! I have just finished reviewing a similar question in the OS.com: http://stackoverflow.com/q/22096468/2556111

1 answer

1


Hello... the problem is in your query. it has in the end an extra parentheses

SqlCeCommand comando = new SqlCeCommand(@"INSERT INTO Pedido([IDLayout], [Vim], [Data], [Quantidade])VALUES(@IDLayout,@Vim,@Data,@Quantidade))", conn);

The right thing would be

SqlCeCommand comando = new SqlCeCommand(@"INSERT INTO Pedido([IDLayout], [Vim], [Data], [Quantidade])VALUES(@IDLayout,@Vim,@Data,@Quantidade)", conn);

Note that at the end of Insert, before ",Conn);" had 2 parentheses ), you need to remove one of them

  • Funny! I just reviewed a similar question in the.com OS: It was you who also gave the answer in http://stackoverflow.com/a/22096508/2556111 ?

  • 1

    No no, the answer wasn’t me, but the owner of the question is the same

  • @ramaral the author of the question followed a suggestion of our own goal, see here, It sure was a question without great challenges, so it seems kind of unfunny. Already the tchicotti did nothing wrong.

  • @Math Thanks for the clarification. By the way I would like to know who voted on the question.

  • @ramaral am man! rs.. Yes, the vote in favor of the question was something very careless, in my opinion. But that’s something I’ve seen often around here in OS Pt.

  • @Math It’s true! I’ve noticed that as soon as the questions come up, they already have a vote in favor. Someone who’s desperate for medals!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.