DataRow変数がコピーできません

こんばんは
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

Hi, @prashant1603765
Thank you for your rely!
How can I copy the value of dr_work to another DataRow, dr_work1?

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.

Your code raised static error as follows. The meaning is "Conversion from object to object□ is not allowed. "
Hope your final answer.

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.

dr_work1.ItemArray = CType(dr_work.ItemArray, Object())

Regards,
Arivu

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

Your code raised static error under the condtion that I defined both dr_work1 and dr_work, as DataRow.

Your code raised dynamic error. Hope your final answer next time.

Can you share the xaml file. Let me check and find out the issue

Try this below use add data row activity

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.

Your suggested activity does not work when I insert a datarow using index number…
I use InsertAt method instead.

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()

Your code raised static error.
The meaning is "Conversion from object to object□ is not allowed. "
Hope your final answer next time.

こんにちは

これはdr_work1がnullだからかと思います。
ItemArrayプロパティを呼び出す前に何らかの手段でdr_work1のインスタンスを生成する必要があります。

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.