简体   繁体   中英

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

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.

Check是保留的SQL关键字,请尝试以下操作:

INSERT INTO [Check]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM