for some reason my code is resulting to syntax error INSERT INTO and its pointing to executenonquery line

                    OleDbCommand cmd = new OleDbCommand(String.Concat("INSERT INTO CHILDREN2 WHERE (Emp_ID , Child_Name, Age ) VALUES ('", Convert.ToInt32(CaptionText.ToString()), "','", txtName.Text, "','", txtAge, ")"), clsData.con);

                catch (Exception ex)

Change this line of code (sql query) into:

OleDbCommand cmd = new OleDbCommand(Stirng.Format("INSERT INTO CHILDREN2 (Emp_ID , Child_Name, Age) VALUES ({0}, {1}, {2})", Convert.ToInt32(CaptionText.Text),txtName.Text, txtAge), clsData.con);

Do you have a WHERE clause too? I removed it from your query, becasue it didnt belonge on that place where you put it.
If you will use a Where clause then create an sql query this was:

"INSERT INTO TableName (Field1, Field2) VALUES (@paramField1, @paramField2) WHERE Field3 = @paramField3"

where params are parameters passed to the fields, and WHERE is a conditional clause, and has to be stated on the end (after specifying parameters).

Edited 5 Years Ago by Mitja Bonca: n/a

OleDbCommand cmd = new OleDbCommand(String.Concat("INSERT INTO CHILDREN2 (Emp_ID , Child_Name, Age ) VALUES ('", Convert.ToInt32(CaptionText.ToString()), "','", +txtName.Text+, "','", +txtAge+, ")"), clsData.con);

if ur EmpId is an int, u dnt have to pass it in quotes, take the query string and check with sql db, u ll know where u r going wrong, how ever, use '+' operator to append the values.

This article has been dead for over six months. Start a new discussion instead.