I am currently working on a system and I have a number of spreadsheet that come in via email and they all hold the same type of data just from different people. I want to be able to upload each of these Excel sheets to a Datagridview. I can get one Excel sheet to populate the DataGridView but when I try to add another it replace the one that is already there.
try
{
System.Data.OleDb.OleDbConnection MyCnn;
System.Data.DataSet DSet;
System.Data.OleDb.OleDbDataAdapter MyCmd;
MyCnn = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtFileName.Text + " ;Extended Properties=Excel 8.0;");
MyCmd = new System.Data.OleDb.OleDbDataAdapter ("SELECT * FROM [Sheet1$]", MyCnn);
//MyCmd.TableMappings.Add("Table", "TestTable");
DSet = new System.Data.DataSet();
MyCmd.Fill(DSet);
dgvSheetView.DataSource = DSet.Tables[0];
MyCnn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}Any Help would be much appreciated.
Thanks