Click here to Skip to main content
15,889,361 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
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:

VB.NET
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


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.
Posted
Updated 4-Sep-17 18:47pm
v4
Comments
W Balboos, GHB 10-Aug-16 7:11am    
Dim excelsheet As [String]() = New [String](dtsheet.Rows.Count - 1) {}

Doesn't look like C# to me.

I'll be a little helpful: if your sheets are not well populated (i.e., no mixed columns of numbers in some rows and characters in others, then your import's going to be quite difficult and uncooperative as the data types will keep changing,

 
Share this answer
 
Comments
Maciej Los 10-Aug-16 16:09pm    
+5 for the link ;)
Mehdi Gholam 11-Aug-16 0:23am    
Thanks Maciej!
To be up to the challenge, you have to follow below steps:

  1. Connect to the Excel sheet using OleDbConnection[^]
  2. Create OleDbCommand[^] to read the data using OleDbDataReader[^]
  3. Load data into DataTable[^]
  4. Disconnect with Excel sheet
  5. Connect to the SQL database using SqlConnection[^]
  6. Copy data into SQL table using SqlBulkCopy class[^]
  7. Disconnect with Sql database


That's all! Try!

Note: Do not loop through the collection of rows in Excel sheet! That is the reason of your problems.
 
Share this answer
 
Comments
Mehdi Gholam 11-Aug-16 0:23am    
5'ed
Maciej Los 11-Aug-16 1:44am    
Thank you, Mehdi.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900