I need to read the excel data and store in database. when I try to read the data, there are some data got missed, I couldn't able to find.
My code :
private string Excel03ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
[![//Get the name of the First Sheet.
using (OleDbConnection con = new OleDbConnection(conStr))
{
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = con;
con.Open();
DataTable dtExcelSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
sheetName = dtExcelSchema.Rows\[0\]\["TABLE_NAME"\].ToString();
con.Close();
}
}
//Read Data from the First Sheet.
using (OleDbConnection con = new OleDbConnection(conStr))
{
using (OleDbCommand cmd = new OleDbCommand())
{
using (OleDbDataAdapter oda = new OleDbDataAdapter())
{
cmd.CommandText = "SELECT * From \[" + sheetName + "\]";
cmd.Connection = con;
con.Open();
oda.SelectCommand = cmd;
oda.Fill(dtExcelData);
con.Close();
//Populate DataGridView.
//dataGridView1.DataSource = dt;
}
}
}
dtExcelData = dtExcelData.AsEnumerable().Skip(2).Take(1).CopyToDataTable();
return dtExcelData;][2]][2]
Data after reading through in oledbConnection :

