Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Importing Data from different Excel Sheets into the same Datagridview without replacing the rows that are already imported before hand.

$
0
0

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



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>