Hi ,
I have an excel with 4L data, i want to upload in DB which is allowed only 100 per upload,
I have developed a project based on my knowlegde, where i have provided the range as static for the first upload, but for future upload the range should be dynamic so that i can upload all the data.
Attached the Xaml for reference.
Main.xaml (11.8 KB)
Thanks in advance.
adiijaiin
(Aditya Jain)
March 25, 2024, 12:29pm
2
Hello @Mohamed_Ameer1
You can use a counter of use skip and Take function in a LINQ query and you can get the batch by batch 100 records.
skipCounter=0
.Skip(skipCounter).Take(100);`
SkipCounter= SkipCounter+100
Thanks
Happy Automation!
ppr
(Peter Preuss)
March 25, 2024, 12:31pm
3
We assume that the project is set to Windows Compatibility
Assign Activity:
TableList | DataType_ List(Of DataTable) =
yourDataTableVar.asEnumerable().Chunk(100).Select(Function (x) x.CopyToDataTable).toList
We get returned a List of DataTables, where each datatable is representing a segment of 100 rows
Parvathy
(PS Parvathy)
March 25, 2024, 12:33pm
4
Hi @Mohamed_Ameer1
=> Read Range Workbook
Output-> dt
=> Use the below condition in Assign:
List_Dt = dt.AsEnumerable.Chunk(100).Select(Function(a) a.CopyToDataTable).ToList
List_Dt
is of DataType System.Collections.Generic.List(System.Data.DataTable)
=> You can use For Each loop to iterate through List_Dt
and push it to Database.
Hope it helps!!
ppr
(Peter Preuss)
March 25, 2024, 12:34pm
5
In older times, before the Chunk operator was introduced, we used Skip / take and did it in this way
@christine.tzenghy
let me introduce a general approach that can be also adopted to more case specific details.
Assumptons:
DataTable with 8 Rows
Segmentsize: 3
Following Building Blocks are used
Calculation of the numbers of segments:
[grafik]
with the Ceiling method the fractions are uprounded to the next Integer
with the Skip() and Take() Method the Rows for a segment can be retrieved.
the different segments are bult by following
[grafik]
and do fetch the different segment rows by: …
Hi @adiijaiin @ppr @Parvathy thanks for your quick response.
I would like to go with the below method, but i am getting an error:
It is better if i have the flow as i am a learner and much appreciated!
ppr
(Peter Preuss)
March 25, 2024, 12:44pm
7
Ensure that the variable Datatype is set to a list (of DataTable)
yes, it is
Note: i have two excel one is input where i have the 4L data, and output to iterate every 100 records as i dont want to modify the input sheet.
Parvathy
(PS Parvathy)
March 25, 2024, 12:49pm
9
Hi @Mohamed_Ameer1
Go to Browse For Types type System.Collections.Generic.List you will find List . In place of T pass System.Data.DataTable.
Check the below image for better understanding:
Regards
Parvathy
(PS Parvathy)
March 25, 2024, 1:29pm
12
Hi @Mohamed_Ameer1
Use For Each loop. Below image will give you a better understanding of the flow. If you are going to write the data to excel then please initialize Counter to 1 . Inside the For Each loop after Write Range Workbook increment the counter by 1.
Check the below image
Regards
ppr
(Peter Preuss)
March 25, 2024, 1:40pm
13
We recommend to have a complete understanding of what is modelled
Minisample
DataTable is segmented within a size of two DataRows.
Within the TableList we do have the splits as segmented DataTables
Therefore we use the For Each Activity for the loop and can process the iterated DataTable
About LINQ:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum
Thank You, it worked but it is also creating empty space in the excel which causes upload failure in DB as it doest not accept space as values.But actual datas are in A and B column only, Could help in figuring out.
Nice, Thank you!
Now I understand the architecture clearly.
ppr
(Peter Preuss)
March 25, 2024, 2:50pm
16
Perfect, as with the very early given approach of chunk(X)
now we can check for cleansings
just share some samples from the
input data
the resultinh output data
along with the elaboration on what is needed, what is to cleanse in which way
@Parvathy Now i got the point, if the input data is less than 100 then it makes empty space untill the loop exist!
Thanks for your help!!
ppr
(Peter Preuss)
March 25, 2024, 2:54pm
18
cannot confirm as we can see:
it is not filled up to the segment size.
Maybe we do misunderstand your statement and you can elaborate more on this
I can understand the situation now, after successfull update in DB i am deleting the data to get the next batch, please refer below screenshot and let me is there any alternate way to handle this?
ppr
(Peter Preuss)
March 25, 2024, 3:08pm
20
ppr:
just share some samples from the
input data
the resultinh output data
along with the elaboration on what is needed, what is to cleanse in which way
please support us on this, then we can check for the fitting options
We do not see so far the need for cleansings, as the data can be used directly