Oledbconnection没有读取完整记录C#

Oledbconnection没有读取完整记录C#

本文介绍了Oledbconnection没有读取完整记录C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





使用(OleDbConnection excel_con = new OleDbConnection(Provider = Microsoft.ACE.OLEDB.12.0; Data Source = FilePath; Extended Properties ='Excel 12.0; HRD = YES; IMEX = 1;'))
{
excel_con.Open();
string sheet1 =;
sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null).Rows [0] [TABLE_NAME]。ToString();

DataTable dtExcelData = new DataTable();
使用(OleDbDataAdapter oda = new OleDbDataAdapter(SELECT * FROM [+ sheet1 +],excel_con))
{
oda.Fill(dtExcelData);
}
excel_con.Close();
}





我的尝试:



我有excel文件,它包含300000条记录。我从excel文件中读取数据并使用以下代码将其转换为datatable。 

此代码有时读取所有记录300000条记录,有时读取238000条。
解决方案



using (OleDbConnection excel_con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=FilePath;Extended Properties='Excel 12.0;HRD=YES; IMEX=1;'"))
{
    excel_con.Open();
    string sheet1 = "";
    sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();

    DataTable dtExcelData = new DataTable();
    using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con))
    {
        oda.Fill(dtExcelData);
    }
    excel_con.Close();
}



What I have tried:

I have excel file , it contains 300000 records. I read data from excel file and convert it to datatable using following code.

This code sometimes read all records 300000 record and sometime 238000.
解决方案


这篇关于Oledbconnection没有读取完整记录C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 07:41