Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
plz help me in this
my data can't inserted
it displaying error "syntax error in INSERT into Statement"
C#
try
            {
                OleDbConnection con;
                OleDbCommand com;
string path = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Documents\Visual Studio2010\Projects\insert1\insert1\bin\Debug\insert.accdb";
                con = new OleDbConnection(path);   
                con.Open();
                MessageBox.Show("connected");
string query = "insert into user(username,password) values ('" + textBox1.Text + "','" + textBox2.Text + "')";
                com = new OleDbCommand(query);
                com.Connection = con;
                if (com.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("data inserted");
                }
                else
                {
                    MessageBox.Show("not inserted");
                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
Posted
Updated 3-Mar-14 5:34am
v2

1 solution

Well, user is a keyword (If I'm not mistaken than it's a inbuilt table) in SQL, So you can't give a table name like that.

But still if you want to, you can, but write the query this way,
C#
string query = "insert into [user] (username,password) values ('" + textBox1.Text + "','" + textBox2.Text + "')";

-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900