如何在datatable中导入大型excel文件 [英] How to import large excel file in datatable
本文介绍了如何在datatable中导入大型excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Vb.net的Datatable中导入大型Excel文件
Excel工作表大小为165 MB。
Excel文件有超过9个Lakhs记录。
我尝试过:
How to Import Large Excel file in Datatable in Vb.net
Excel Sheet Size will be 165 MB.
Excel File Having a More Than 9 Lakhs Records.
What I have tried:
Dim excelsheet As [String]() = New [String](dtsheet.Rows.Count - 1) {}
Dim i As Integer = 0
For Each row As DataRow In dtsheet.Rows
excelsheet(i) = row("TABLE_NAME").ToString()
Dim da As New OleDb.OleDbDataAdapter("Select * " + _
" From [" + excelsheet(i) + "]", strCon)
da.Fill(ds)
Exit For
i += 1
Next
填充数据集大约5000到6000行,但有Excel中有9万行。
OleDbDataAdapter读取的不完整文件。
给我一个解决方案。
i也使用Sql Import facil ity,但它不起作用。
Fill Dataset Some 5000 to 6000 rows but there are 9 lakhs Row in Excel.
Not Full File Read by OleDbDataAdapter.
give me a Solution.
i also use Sql Import facility, but it will not work.
推荐答案
改为尝试: EPPlus-Create advanced服务器上的Excel电子表格 - 主页 [ ^ ]
要接受挑战,您必须按照以下步骤操作:
To be up to the challenge, you have to follow below steps:
- 使用<连接到Excel工作表a href =https://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection(v=vs.110).aspx> OleDbConnection [ ^ ]
- 创建 OleDbCommand [ ^ ]使用 OleDbDataReader [ ^ ]
- 将数据加载到DataTable [ ^ ]
- 与Excel表断开连接
- 使用 SqlConnection [ ^ ]
- 使用SqlBu lkCopy类 [ ^ ]
- 断开与Sql数据库的连接
- Connect to the Excel sheet using OleDbConnection[^]
- Create OleDbCommand[^] to read the data using OleDbDataReader[^]
- Load data into DataTable[^]
- Disconnect with Excel sheet
- Connect to the SQL database using SqlConnection[^]
- Copy data into SQL table using SqlBulkCopy class[^]
- Disconnect with Sql database
这就是全部!试试吧!
注意:不要遍历Excel表格中的行集合!这就是你遇到问题的原因。
这篇关于如何在datatable中导入大型excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文