gorby
(gorby)
March 13, 2025, 2:15pm
1
こんばんは
UiPath Studio 2025.0.161 Community editionのユーザです。
1.やりたいこと
DataRow変数dr_workを別のDataRow変数dr_work1にコピーしたい。
2.悩んでいること
デバッグ実行時に、DataRow変数dr_workに下記の値があることを確認したうえで、
DataRow { HasErrors=false, ItemArray=object[4] { "常陸太田市", "ひたちおおたし", 44743, 371.99 }, RowError="", RowState=Added, Table=[DataTable] }
dr_work1.ItemArray=dr_work.ItemArray
を実行すると添付のエラーが出ました。どうしてでしょうか?
Hi @gorby
The issue occurs because dr_work.ItemArray returns an array of objects (object ). When you assign dr_work1.ItemArray = dr_work.ItemArray, you are not creating a new DataRow but only copying the reference to the same object array. If the DataRow structure is inconsistent (e.g., different table schema), an error can occur
gorby
(gorby)
March 13, 2025, 9:55pm
3
Hi, @prashant1603765
Thank you for your rely!
How can I copy the value of dr_work to another DataRow, dr_work1?
arivu96
(Arivazhagan A)
March 13, 2025, 10:08pm
4
Hi @gorby ,
dr_target.ItemArray = dr_work.ItemArray.Clone()
This copies all values from dr_work to dr_target in one step.
Regards,
Arivu
Hi @gorby
Use below expression -
ItemArray = dr_work.ItemArray.Clone()
This method efficiently transfers all column values from dr_work to dr_work1.
gorby
(gorby)
March 14, 2025, 2:24am
6
Your code raised static error as follows. The meaning is "Conversion from object to object□ is not allowed. "
Hope your final answer.
gorby
(gorby)
March 14, 2025, 2:27am
7
Does your code contain typo?
If your code is
dr_work1.ItemArray = dr_work.ItemArray.Clone()
your code raised static error.Hope your final answer.
arivu96
(Arivazhagan A)
March 14, 2025, 2:30am
8
dr_work1.ItemArray = CType(dr_work.ItemArray, Object())
Regards,
Arivu
arivu96
(Arivazhagan A)
March 14, 2025, 2:31am
9
Ensure Both Variables Are of the Same Type
Check the variable types of dr_work1 and dr_work.
If dr_work1.ItemArray is an array (Object()), make sure dr_work.ItemArray is also an Object() and not just Object.
You can define dr_work1 as DataRow explicitly.
Regards,
Arivu
gorby
(gorby)
March 14, 2025, 2:41am
10
Your code raised static error under the condtion that I defined both dr_work1 and dr_work, as DataRow.
gorby
(gorby)
March 14, 2025, 2:57am
11
Your code raised dynamic error. Hope your final answer next time.
arivu96
(Arivazhagan A)
March 14, 2025, 2:58am
12
Can you share the xaml file. Let me check and find out the issue
Try this below use add data row activity
The UiPath Documentation Portal - the home of all our valuable information. Find here everything you need to guide you in your automation journey in the UiPath ecosystem, from complex installation guides to quick tutorials, to practical business...
Hi @gorby
Try this expression -
dr_work1.ItemArray = DirectCast(dr_work.ItemArray.Clone(), Object())
@gorby
If both dr_work and dr_work1are of type DataRow, you should use this expression to avoid the implicit conversion error under Option Strict On:
dr_work1.ItemArray = CType(dr_work.ItemArray.Clone(), Object())
or
dr_work1.ItemArray = DirectCast(dr_work.ItemArray.Clone(), Object())
This ensures the cloned ItemArray is correctly assigned as an Object() array.
gorby
(gorby)
March 14, 2025, 3:07am
15
Your suggested activity does not work when I insert a datarow using index number…
I use InsertAt method instead.
gorby
(gorby)
March 14, 2025, 3:11am
16
Your code raised the dynamic error as folows.
代入: Object reference not set to an instance of an object.
@gorby
The error “Object reference not set to an instance of an object” occurs because dr_work1 is Nothing (null) and hasn’t been initialized before assigning values.
Before assigning ItemArray, create a new DataRow instance using its parent DataTable:
dr_work1 = dr_work.Table.NewRow()
dr_work1.ItemArray = dr_work.ItemArray.Clone()
gorby
(gorby)
March 14, 2025, 3:41am
19
Your code raised static error.
The meaning is "Conversion from object to object□ is not allowed. "
Hope your final answer next time.
Yoichi
(Yoichi)
March 14, 2025, 4:18am
20
こんにちは
これはdr_work1がnullだからかと思います。
ItemArrayプロパティを呼び出す前に何らかの手段でdr_work1のインスタンスを生成する必要があります。
system
(system)
Closed
March 17, 2025, 4:18am
21
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.