I am trying to insert data from exel files to Microsoft SQL server local db table. I can show a dataGridview with the excel data in a windows form application but I cant figure out how to put the data into a table.
try
{
System.Data.OleDb.OleDbConnection cnn;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter cmd;
cnn = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\\CGData\\user\\Desktop\\Book1.xls';Extended Properties = Excel 8.0");
cmd = new System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", cnn);
cmd.TableMappings.Add("Table", "TestTable");
DtSet = new System.Data.DataSet();
cmd.Fill(DtSet);
dataGridView1.DataSource = DtSet.Tables[0];
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
What Else do I need to do to copy the Data into a localDB Database table?