Insert into access 2007 database
Hi everyone
I am trying to use the code below to insert data into my access database, in the database I have set wkno and yr values as "number" and dat as "date/time" all the rest are set as "text" values. When I run the code below I get an error "Syntax error in INSERT INTO statement."
DateTime date = Convert.ToDateTime(textBox4.Text);
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\katoto\Documents\Visual Studio 2010\Projects\Genesis Philcollins\data\thyfarm.accdb;Jet OLEDB:Database Password=Kyozi");
conn.Open();
string insertString = "insert into Herdregistar (day,dat,wkno,mont,yr,motheruic,mother,animalsex,uic,nam,tagno,status,owner,presence) values ('" + textBox3.Text + "','" + DateTime.Parse(textBox4.Text).ToString("dd/MM/yyyy") + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + comboBox3.Text + "','" + textBox11.Text + "','" + textBox12.Text + "','" + textBox13.Text + "','" + comboBox1.Text + "','" + textBox15.Text + "','" + comboBox4.Text + "')";
OleDbCommand cmd = new OleDbCommand(insertString, conn);
cmd.ExecuteNonQuery();
conn.Close();
please help me.
thanks