我需要读取excel数据并存储在数据库中。 当我尝试读取数据时,有一些数据被遗漏,我无法找到。
我的代码:
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]
在oledbConnection中阅读后的数据: