i get that error when i try and run through my code.

Can any one please tell me what is wrong with my insert statement.
It looks correct.

OleDbConnection connect = new OleDbConnection();
            connect = new DBconnect().DbConn("");


            string insertStatement = "INSERT INTO Restrict "
             + "([Company ID], [User Type], [Company]) "
             + "VALUES (?,?,?)";

            OleDbCommand insertCommand = new OleDbCommand(insertStatement, connect);

      insertCommand.Parameters.Add("[Company ID]", OleDbType.Char).Value = textBox3.Text;
     insertCommand.Parameters.Add("[User Type]", OleDbType.Char).Value = comboBox16.Text;
       insertCommand.Parameters.Add("[Company]", OleDbType.Char).Value = comboBox9.Text;
                

            connect.Open();

            int count = insertCommand.ExecuteNonQuery();
            connect.Close();

please post if you think it looks correct.

Generally you put @ in front of parameters. And since OleDB is positional, it doesn't matter what you call them:

insertCommand.Parameters.Add("@ID", OleDbType.Char).Value = textBox3.Text;
insertCommand.Parameters.Add("@Type", OleDbType.Char).Value = comboBox16.Text;
insertCommand.Parameters.Add("@Company", OleDbType.Char).Value = comboBox9.Text;

Generally you put @ in front of parameters. And since OleDB is positional, it doesn't matter what you call them:

insertCommand.Parameters.Add("@ID", OleDbType.Char).Value = textBox3.Text;
insertCommand.Parameters.Add("@Type", OleDbType.Char).Value = comboBox16.Text;
insertCommand.Parameters.Add("@Company", OleDbType.Char).Value = comboBox9.Text;

No i figured it out. Its because the word Restrict is a reserved word.
So i need brackets around it.

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