Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create a module which upload text file, then suddenly I encounter error of out of memory. I realize that I reach the maximum size of file to be uploaded.

Now, I'm attempting to split my DataTable into many DataTables. When I run the code to debug, I encouter error
Quote:
Unable to cast object of type 'System.Data.DataRow[]' to type 'System.Data.DataTable'


What I have tried:

Dim _New_dt As New DataTable()
Dim dtArr() As DataTable = Nothing
Dim Columns As DataRow = dt.NewRow

_New_dt = dt.Copy
_New_dt.Columns.Add("Key_Id", GetType(String))

Dim c = _New_dt.Rows.Count / 30000
Dim SheetNumber = Convert.ToInt64(System.Math.Ceiling(c))


For j As Integer = 0 To c

dtArr(j) = _New_dt.Select("Key_Id <= 1 And Key_Id >= 30000").Clone()
dtArr(j) = _New_dt.Select("Key_Id <= 31000 And Key_Id >= 60000").Clone()
dtArr(j) = _New_dt.Select("Key_Id <= 61000 And Key_Id >= 90000").Clone()
dtArr(j) = _New_dt.Select("Key_Id <= 91000 And Key_Id >= 120000").Clone()
dtArr(j) = _New_dt.Select("Key_Id <= 121000 And Key_Id >= 150000").Clone()

Next
Posted
Updated 12-Mar-18 17:09pm
v2

1 solution

I anwered your question already: How to split a large datatable into multiple datatables in ASP.NET[^]. There you'll find a way how to copy an array of datarows into another datatable.
 
Share this answer
 
Comments
Laxmidhar tatwa technologies 12-Mar-18 23:05pm    
Retrieve the data row one by one from and store
One by one data row of another datatable
1DSparrows 12-Mar-18 23:08pm    
I already got it corrected, thanks
Maciej Los 13-Mar-18 2:59am    
You're very welcome.
Maciej Los 13-Mar-18 2:59am    
Do you mean via using a loop? Why? CopyToDataTable is faster than loop.
Laxmidhar tatwa technologies 13-Mar-18 5:14am    
Hi Maciej los
You r currect

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