Why cant i insert into access database?
Posted on 2006-05-30
i have eightcolumns in my access database. one is an autonum. I want to insert the values from my form into the database but i keep getting an error saying that my insert statement is incorrect. does anyone know what im doing wrong?
OleDbConnection Myconnection = null;
Myconnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=C:\Database.mdb");
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "INSERT INTO Users (Name,Surname,DOB,Gender,Smoker,State,Note) VALUES ('" + txtName.Text + "', '" + txtSurname.Text +"', '" + txtDateofBirth.Text +"', '" + rdbGender.SelectedValue +"','" + rdbSmoker.SelectedValue +"','" + DropDownState.SelectedValue +"','" + txtNote.Text +"')";