private void button2_Click(object sender, EventArgs e)
{
try
{
string cnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Sanjay\\Documents\\Database1.accdb";
OleDbConnection conGet = new OleDbConnection(cnString);
OleDbCommand cmdGet = new OleDbCommand ("INSERT INTO ItemM (Sr,Cust,Icc,Shirt,SShirt,Pant,SPant,Salwar,SchoolShirt,SchoolPant,Saree,Top,Dupatta,Blause,Paijama,Kurta,Frock,Cot,Sherwani,Others,Ammount,RDate,DDate,Delvery Status,Bill Status,Paid,Balance)values('" + label30.Text + "', '" + textBox3.Text + "', '" + textBox7.Text + "', '" + textBox8.Text + "', '" + textBox9.Text + "', '" + textBox10.Text + "', '" + textBox11.Text + "', '" + textBox12.Text + "', '" + textBox13.Text + "', '" + textBox14.Text + "', '" + textBox15.Text + "', '" + textBox16.Text + "', '" + textBox17.Text + "', '" + textBox18.Text + "', '" + textBox19.Text + "', '" + textBox20.Text + "', '" + textBox21.Text + "', '" + textBox22.Text + "', '" + textBox23.Text + "', '" + textBox60.Text + "', '" + textBox1.Text + "', '" + textBox1.Text + "', '" + textBox61.Text + "', '" + textBox62.Text + "', '" + textBox63.Text + "', '" + textBox60.Text + "')", conGet);
conGet.Open();
cmdGet.ExecuteNonQuery();
conGet.Close();
}
catch
{
MessageBox.Show ("Record not inserted");
}
}
Raja TPosted Jul 26, 2015, 3:23 AM
Please check out bellow URL
http://stackoverflow.com/questions/30019828/syntax-error-in-insert-into-statement-when-adding-record-to-access-database
Top is a reserved keyword. Add brackets around the name to specify that it's an identifier
Try like
OleDbCommand cmdGet = new OleDbCommand ("INSERT INTO ItemM (Sr,Cust,Icc,Shirt,SShirt,Pant,SPant,Salwar,SchoolShirt,SchoolPant,Saree,[Top],Dupatta,Blause,Paijama,Kurta,Frock,Cot,Sherwani,Others,Ammount,RDate,DDate,Delvery Status,Bill Status,Paid,Balance)values('" + label30.Text + "', '" + textBox3.Text + "', '" + textBox7.Text + "', '" + textBox8.Text + "', '" + textBox9.Text + "', '" + textBox10.Text + "', '" + textBox11.Text + "', '" + textBox12.Text + "', '" + textBox13.Text + "', '" + textBox14.Text + "', '" + textBox15.Text + "', '" + textBox16.Text + "', '" + textBox17.Text + "', '" + textBox18.Text + "', '" + textBox19.Text + "', '" + textBox20.Text + "', '" + textBox21.Text + "', '" + textBox22.Text + "', '" + textBox23.Text + "', '" + textBox60.Text + "', '" + textBox1.Text + "', '" + textBox1.Text + "', '" + textBox61.Text + "', '" + textBox62.Text + "', '" + textBox63.Text + "', '" + textBox60.Text + "')", conGet);