Click here to Skip to main content
15,301,841 members
Please Sign up or sign in to vote.
2.77/5 (4 votes)
See more:
I'm getting error when i try to insert data into a access database..
missing semicolon (;) at the end of sql statement..
anyone can help me?
p.s i try to put the semicolon at the end but same error again..
the insert command is here :


C#
oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "') where emri = '" + listBox1.SelectedItem + "'";
            oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
Posted
Updated 22-Sep-13 12:18pm
v2
Comments
[no name] 22-Sep-13 10:57am
   
"insert into magazina(sasia) values ('" + sasia_totale + "') where emri = '" + listBox1.SelectedItem + "'";
Emin Kokalari(EAK) 22-Sep-13 18:15pm
   
the end of statement is : where emri = '"+listBox1.SelectedItem+"'";
i made mistake in writing statement... sorry for this, but my problem still exist !..
[no name] 22-Sep-13 19:04pm
   
Probably because whatever database you are using might not support an INSERT statement with a WHERE clause.
Emin Kokalari(EAK) 23-Sep-13 5:48am
   
im using access database

Too many double quotes!
Change:
C#
oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "') where emri = '" + listBox1.SelectedItem + '"";
To:
C#
oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "') where emri = '" + listBox1.SelectedItem + "'";
   
v2
Comments
Emin Kokalari(EAK) 22-Sep-13 18:18pm
   
The problem still exist bro...
Dave Kreskowiak 22-Sep-13 22:49pm
   
A WHERE clause with an INSERT query?? I don't know of a single DB engine that supports that! ;)
You cannot use a WHERE clause with an INSERT statement.

I think you need to change this query to an UPDATE statement.

Also, you should probably Google for "SQL Injection Attack" to find out why using string concatentation to build your SQL statement is a horrible idea and what you can do to fix it. Another Google search would be "C# SQL parameterized query".
   
Try below one :

SQL
oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "')
                where emri = '" + listBox1.SelectedItem + "'";


I hope this will help to you.
   
Comments
Emin Kokalari(EAK) 22-Sep-13 18:19pm
   
this statement its not correct...

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