Oledbconnection没有读取完整记录C# [英] Oledbconnection not reading full records C#

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

问题描述

Quote:

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



此代码有时会读取所有记录300000条记录,有时读取238000条。





使用(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条。

解决方案

我认为该行代码应阅读:

使用(OleDbConnection excel_con = new OleDbConnection(Provider = Microsoft.ACE.OLEDB.12.0; Data Source = FilePath; Extended Properties ='Excel 12.0;  HDR = YES; IMEX = 1 ;'))

注意拼写 HDR 不是 HRD


Quote:

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.



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.

解决方案

I think that line of code should read:

using (OleDbConnection excel_con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=FilePath;Extended Properties='Excel 12.0;HDR=YES;IMEX=1;'"))

Note the spelling HDR not HRD


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆