1

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;
  }
}
6
  • 5
    What is the exception details? Commented Sep 18, 2013 at 12:54
  • 2
    is the transaction id column an auto generated column? if so then you shouldnt set it in the insert statement Commented Sep 18, 2013 at 12:56
  • what error message are you getting? Commented Sep 18, 2013 at 12:56
  • paste the error message and stack trace Commented Sep 18, 2013 at 12:59
  • Soner- There was an error parsing the query. [ Token line number = 1,Token line offset = 13,Token in error = Check ] Commented Sep 18, 2013 at 12:59

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It escapes the word, telling SQL that it should be interpreted as an identifier rather than a reserved word. This is also used when referring to entities that, for example, have spaces in the name.
2

Check is a reserved SQL keyword, try this:

INSERT INTO [Check]

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.