string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileAddress + ";Extended Properties='Excel 12.0 XML;HDR=Yes;IMEX=1'"; using (OleDbConnection conn = new OleDbConnection(excelConnectionString)) { if (conn.State != ConnectionState.Open) conn.Open(); //I have error 'Invalid argument.' OleDbDataAdapter objDA = new System.Data.OleDb.OleDbDataAdapter ("select * from [ثبت$]", conn); DataSet excelDataSet = new DataSet(); objDA.Fill(excelDataSet); dataGridView1.DataSource = excelDataSet.Tables[0]; } using (OleDbConnection conn = new OleDbConnection(excelConnectionString)) { try { conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandText = @"Insert into [ثبت$] (month,mango,apple,orange) VALUES ('DEC','40','60','80');"; cmd.ExecuteNonQuery(); } catch (Exception ex) { //exception here } finally { conn.Close(); conn.Dispose(); } }
FileAddress
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)