I got the following error in my code today:
Syntax error in INSERT INTO statement.

OleDbCommand cmd = new OleDbCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText="Insert into Cursanti([ID],[Nume],[Prenume],[Sex],[Varsta],[Ziua-1],[Ziua-2],[Ora-1],[Ora2],[E-mail],[Telefon],[Referal],[Partic/Grup],[Adult/Copil)] Values ('"+id_b.Text+"','"+name_t.Text+"','"+surname_t.Text+"','"+sex+"',"+age_t.Text+"','"+ziua1.Text+"','"+ziua2.Text+"','"+ora1.Text+"','"+ora2.Text+"','"+email_b.Text+"','"+phone_b.Text+"','"+from_t.Text+"','"+ore+"','"+categorie+"')";
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

The error points at "cmd.ExecuteNonQuery();"

Searched the other topics, saw that people had similar problems, but i didn't quite get what should be done. It's my first day working with databases as well so sorry if it's a silly question.

Things i did to try and solve the problem:
1. Added [] for each ID, Nume etc.
2. Checked if the types are all the same.
3. Checked for anything typed wrong.

Sorry for some of the code, but used romanian in my project.

Oh and yea, if i just add a dateTimePicker to the form that i'm using, is it ok if i use the same example as above to store the date? like "+dateTimePicker1.Value+".

Tell me if you need any other info.

Looks like you're missing a closing parenthesis right before the word VALUES
...or that it's inside the ] bracket instead of outside.

Dooh.. thx, that solved it...
As well, had a few more errors. And in the end it looks like this:

OleDbCommand cmd = new OleDbCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText="Insert into Cursanti([ID],[Nume],[Prenume],[Sex],[Varsta],[Ziua-1],[Ziua-2],[Ora-1],[Ora-2],[E-mail],[Telefon],[Referal],[Partic/Grup],[Adult/Copil]) Values ('"+id_b.Text+"','"+name_t.Text+"','"+surname_t.Text+"','"+sex_t.Text+"','"+age_t.Text+"','"+ziua1.Text+"','"+ziua2.Text+"','"+ora1.Text+"','"+ora2.Text+"','"+email_b.Text+"','"+phone_b.Text+"','"+from_t.Text+"','"+ore+"','"+categorie+"')";
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

I'm happy now :D Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.