Hi I have an array of DataTable and I would like to exact copy my DataTable created into the array. Is it possible?
If you want to copy a datatable:
myNewDT = DT.Copy()
If you want to create a datatable from an array of datarows:
myNewDT = myArray.CopyToDataTable()
Assigning a variable with type System.Data.DataRow()
(a datarow array) to DtData.Select
will create an array of rows from datatable DtData
.
Could you please try before your assignment:
Assign (DataTable)
dtTemp = dtLineItem.Copy()
?
Seems like there is an issue when assigning datatable to an array of datatable. When I tried to assign to a single datatable itโs fine
And
Log Message
dtArray.Length.ToString
?
the message states that your index is beyond the array limit. Are your trying to build an array or to update an already existing member of the array?
Iโm trying to build an array. I declared the array as variables and later on I assigned it with my datatable
You could build a List with default as New List(Of DataTable)
, add your datatables to the list then convert it later to an Array if necessary.
Iโm convinced the problem is with your arrayโs initialisation.
EDIT: Iโm discovering VB with UiPath and just find out about DataSet: might be a better structure. Iโll dig into it tonight.
Alright thank you so much for your help @msan
Hello,
While DataSet is very neat, it might not suit your approach.
If you know the number of item your array will have, you might do:
Assign (Int32)
intArrayLength = ?
Assign (Array Of DataTable)
dtArray = New DataTable(intArrayLength){}
Your array will be ready for your loop.
If you donโt know how many items youโll have, create first a list, add each item in your loop then if necessary convert the list to an array:
Assign (List Of DataTable)
dtList = New List(Of DataTable)
Loop
-
(whatever you need)โฆ
-
AddToCollection
Type of argument: DataTable
Collection: dtList
Item: dtLineItem.Copy() -
(whatever you need)โฆ
// If needed
Assign (Array Of DataTable)
dtArray = dtList.ToArray
Hi @Seungwan !
To make an exact copy of a DataTable into an array of DataTable in UiPath, you can use the following steps:
-
Declare an array of DataTable with the desired size:
- Use the
Assign
activity to create an array variable of DataTable type with the desired size. For example:
ArrayVar = New DataTable[ArraySize]
- Use the
-
Copy the DataTable into the array:
- Use the
Assign
activity to copy the DataTable into the array at the desired index. For example, if you want to copySourceDataTable
into index 0 of the array:
ArrayVar(0) = SourceDataTable.Clone() ArrayVar(0).Merge(SourceDataTable)
- Use the
-
Repeat the above steps for each DataTable you want to copy into the array, adjusting the index accordingly.
By following these steps, you can create an exact copy of a DataTable and store it in an array of DataTable in UiPath.