When a table name or column name contains a space or it is a reserved word you need to enclose that name in square brackets to avoid confusing the sql parser called to interpret your command.
In your context you should write
command.CommandText = "INSERT INTO [statement workers] values(?,?,?,?,?,?,?,?,?)";
EDIT
After looking at your field's name (and assuming that the order of fields is exactly as you have typed them) then you should change the order in which you add your parameters to match exactly the order of the fields in your table.
OleDb cannot use named placeholders to setup the parameter collection and thus, it is important to strictly follow the field order.
If you don't do it then a value could end up in a different field and create problems like when you try to store a decimal value in a date field. (Of course if you add the column names after the table name the order could be changed)
command.Connection = connection;
command.CommandText = "INSERT INTO statement workers values(?,?,?,?,?,?,?,?,?)";
command.Parameters.Add("@Tab", OleDbType.Integer).Value = Convert.ToInt32( tabtextBox1.Text);
command.Parameters.Add("@User", OleDbType.VarWChar).Value = usertextBox2.Text;
command.Parameters.Add("@Pass", OleDbType.VarWChar).Value = passtextBox4.Text;
command.Parameters.Add("@Names", OleDbType.VarWChar).Value = namestextBox3.Text;
command.Parameters.Add("@Tele", OleDbType.Integer).Value = Convert.ToInt32(teletextBox6.Text);
command.Parameters.Add("@Job", OleDbType.VarWChar).Value = jobtextBox9.Text;
command.Parameters.Add("@Date", OleDbType.Date).Value = dateofdateTimePicker2.Value;
command.Parameters.Add("@DOB", OleDbType.Date).Value = dateTimePicker1.Value);
command.Parameters.Add("@Pay", OleDbType.Decimal).Value = Convert.ToDecimal(paytextBox7.Text);
command.ExecuteNonQuery();
In this way you set the values in the exact order expected by the table fields.
Notice that I have removed the dangerous AddWithValue
with a more precise Add
followed by the datatype expected by the field.
AddWithValue cannot know what is the type expected by the database and thus looks at the type of the parameter. Since you pass all strings then the database engine is forced to convert them back to the expected field type.
Sometime (in particular with dates and decimal fields) this doesn't work correctly.
Side notes:
- Telephone numbers should not be stored as numbers, they are not.
- From a security point of view, a password should never be stored in
clear text.There are many articles that explain how this is dangerous and how to hash a password. You could start your search from here: Best way to store password in database