DataGrid Excel and editing the content of the Excel file

  • Thread starter Thread starter MrFlinstone
  • Start date Start date
M

MrFlinstone

Guest
Hi All,


I'm just a learner within C#, I have managed to write an application which loads an excel file using datagrid viewer. The work looks like what I want to do, however the next stage is to allow one to edit the contents of the Excel file via the datagrid viewer.

So basically, I can select a row and edit it and be able to save it, or perhaps delete a row and the changes to be reflected in the actual Excel file. Here is what I have so far and was hoping someone can put me through, could even be that its not possible to do what I want here.

private void Form1_Load(object sender, EventArgs e)
{
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='H:\\Log.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Project$]", MyConnection);
MyCommand.TableMappings.Add("Table", "TestTable");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
dataGridView1.DataSource = DtSet.Tables[0];
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}

}

Continue reading...
 
Back
Top