Akemi Chou
Akemi Chou

Reputation: 64

Syntax Error in INSERT INTO Statement (Insert Records)

can someone help me what is wrong with my code? It always says "Syntax error in INSERT INTO statement. "

try
        {

            OleDbConnection Con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\MotoFix.mdb;");



            Con.Open();
            OleDbCommand Com = new OleDbCommand();

            Com.Connection = Con;
             Com.CommandText = "INSERT INTO Order VALUES ('" + txtRandomOrder.Text + "','" + txtCode.Text + "')";
              Com.ExecuteNonQuery();
             Con.Close();
        }
        catch (Exception ex)
        {
            XtraMessageBox.Show(ex.Message);
        }

Upvotes: 0

Views: 71

Answers (1)

Karthik Ganesan
Karthik Ganesan

Reputation: 4242

Order is a keyword in msaccess refer this link

http://office.microsoft.com/en-us/access-help/access-2007-reserved-words-and-symbols-HA010030643.aspx

change your statement to

"INSERT INTO [Order] VALUES ('" + txtRandomOrder.Text + "','" + txtCode.Text + "')";

and see if it works

Upvotes: 2

Related Questions