Sanjay T

Sanjay T

  • NA
  • 1
  • 654

How do i insert record in access file with ACE 12.0

Jul 26 2015 2:15 AM
I have written a code to insert new record in access 2007 file but i got a exception as "Syntax error in 'INSERT INTO ' statement record does not get added. Please let me know what is wrong in below code.
 

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");

}

}

 

Answers (1)