Ilkin East

Ilkin East

  • NA
  • 100
  • 174.1k

Excel

Apr 29 2012 2:24 AM
Hi,

I want to insert data from my application to existing excel file.When I try I get error message <Operation must use an updateable query>.
My code :
public void button2_Click(object sender, EventArgs e)
{

OleDbConnection con;
OleDbCommand com = new OleDbCommand();
string sql = null;
con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + op.FileName + ";Extended Properties='Excel 12.0 Xml;HDR=YES';");
con.Open();
com.Connection = con;
sql = "Insert into [Sheet1$] (Name,Surname,PC) Values ('Jack','Nana','9')";
com.CommandText = sql;
com.ExecuteNonQuery();
con.Close();
}

Thanks In advance

Answers (1)