Vnz Dichoso
Vnz Dichoso

Reputation: 182

C# SQL Server CE error at parsing the query

I can't seem to find my error at my code. I copy-pasted it with another one of my codes and just change the table and column names.

It states the error at : "int result = cma.ExecuteNonQuery();"

public bool SaveCheckAmount(string id, int amount, string number, string bank)
{
  conn.Open();

  SqlCeCommand cma = new SqlCeCommand("INSERT INTO Check (transactionID,Amount,CheckNumber,Bank)VALUES(@id,@amount,@number,@bank)",conn);
  cma.Parameters.Add("@id",id);
  cma.Parameters.Add("@amount",amount);
  cma.Parameters.Add("@number",number);
  cma.Parameters.Add("@bank",bank);

  int result = cma.ExecuteNonQuery();

  if(result > 0)
  {
    conn.Close();
    return true;
  }
  else
  {
    conn.Close();
    return false;
  }
}

Upvotes: 1

Views: 195

Answers (2)

Colm Prunty
Colm Prunty

Reputation: 1620

Check is a reserved SQL keyword, try this:

INSERT INTO [Check]

Upvotes: 2

3Dave
3Dave

Reputation: 29061

Try changing this to

SqlCeCommand cma = new SqlCeCommand("INSERT INTO [Check] (transactionID,Amount,CheckNumber,Bank) VALUES (@id,@amount,@number,@bank)",conn);

Check is a reserved word in T-SQL.

See this page on MSDN for a complete list.

Upvotes: 3

Related Questions