# How to convert a one-dimensional String array into a System.Data.DataTable

**URL:** <https://forum.uipath.com/t/string-1-system-data-datatable/2858601>\
**Category:** フォーラム\
**Tags:** question, studio, excel\
**Created:** [June 19, 2025, 2:06am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601 "2025-06-19T02:06:01Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![K1111111](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@K1111111](https://forum.uipath.com/u/K1111111)\
**Post date:** [June 19, 2025, 2:06am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/1 "2025-06-19T02:06:01Z")

</div>

Hello.  
I am a user of UiPath Studio 2022.4.6.  
I created the following workflow to filter by multiple conditions listed in an Excel sheet.  
At step ⑤, I get the following error for variable B. Could you please advise me on how to resolve it?  
Error: “Cannot convert a value of type String to System.Data.DataTable”  
① Assign the multiple conditions listed in the Excel sheet to variable A.  
② variable B = variable A.Split(","c)  
③ Read data from a sheet in the target Excel file  
④ Copy the original data and create a new table  
⑤ Repeat for each element in variable B using ForEach  
(set the iteration variable to condition)  
⑥ Select only the rows from the original table where the value in column “A” matches condition, and put the results in filterResultTable  
⑦ Assign the contents of filterResultTable to ResultTable

---

<div class="post-metadata">

**Author:** ![gorby](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gorby/32/543563_2.png) [@gorby](https://forum.uipath.com/u/gorby)\
**Post date:** [June 19, 2025, 2:17am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/2 "2025-06-19T02:17:14Z")

</div>

> [@K1111111](#):
>
> Select only the rows where the value in column “A” matches the condition

Are you trying to filter a data table?  
If so, LINQ makes it easy (it only takes one Assign activity).

For example, assuming the column name is (“reading”), the code below extracts from dt1 to dt2 the rows where (“reading”).ToString = “おおさかし”. You can use AndAlso or OrElse to combine multiple conditions.

`dt2=dt1.AsEnumerable.Where(Function(row) row("reading").ToString = "おおさかし").CopyToDataTable()`

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [June 19, 2025, 2:38am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/3 "2025-06-19T02:38:44Z")

</div>

Hello

> [@K1111111](#):
>
> At step ⑤, I get the following error for variable B. Could you please advise me on how to resolve it?  
> Error: “Cannot convert a value of type String() to System.Data.DataTable”

Could you be using the ForEachRow activity instead of the ForEach activity? Try using the ForEach activity and setting TypeArgument to String.

---

<div class="post-metadata">

**Author:** ![K1111111](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@K1111111](https://forum.uipath.com/u/K1111111)\
**Post date:** [June 19, 2025, 2:42am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/4 "2025-06-19T02:42:44Z")

</div>

Thank you for your reply.  
What I want to do is extract a data table.  
To explain in more detail, I want to filter the extracted Excel data by the specified department codes and delete the matching rows. After deleting them, I want to leave the filter applied.  
The [department codes] to be deleted are listed in comma-separated format in Information.xlsx.  
The reason for preparing Information.xlsx is that the department codes to be deleted may change, so I want the robot to continue working correctly when the codes are changed in Excel.  
That’s it.

---

<div class="post-metadata">

**Author:** ![gorby](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gorby/32/543563_2.png) [@gorby](https://forum.uipath.com/u/gorby)\
**Post date:** [June 19, 2025, 2:49am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/5 "2025-06-19T02:49:52Z")

</div>

> [@K1111111](#):
>
> I want to select the specified affiliation code in the filter and delete it.

Since deleting is the opposite of filtering, you can delete it by negating the condition with Not.  
For example, the code below extracts rows from dt1 to dt2, excluding rows where (“所属コード”)=“12345”.

`dt2=dt1.AsEnumerable.Where(Function(row) Not row("所属コード").ToString = "12345").CopyToDataTable()`

If this answer was helpful, please check Solution. 😃

---

<div class="post-metadata">

**Author:** ![gorby](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gorby/32/543563_2.png) [@gorby](https://forum.uipath.com/u/gorby)\
**Post date:** [June 19, 2025, 2:58am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/6 "2025-06-19T02:58:19Z")

</div>

> [@K1111111](#):
>
> The [affiliation codes] to be deleted are listed in Information.xlsx, separated by commas.

This part is unclear. Are multiple affiliation codes entered in a single cell, separated by commas? Or are the affiliation codes listed vertically in a single column?

---

<div class="post-metadata">

**Author:** ![K1111111](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@K1111111](https://forum.uipath.com/u/K1111111)\
**Post date:** [June 19, 2025, 3:00am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/7 "2025-06-19T03:00:53Z")

</div>

A single cell contains multiple affiliation codes, separated by commas.

---

<div class="post-metadata">

**Author:** ![gorby](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gorby/32/543563_2.png) [@gorby](https://forum.uipath.com/u/gorby)\
**Post date:** [June 19, 2025, 3:11am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/8 "2025-06-19T03:11:34Z")

</div>

I think it’s best to avoid handling data in such a complicated way if you want to make future maintenance easier, but if you need to do it as things stand, first get the cell value into str\_var.

```auto
arr_str = System.Text.RegularExpressions.Regex.Split(str_var, ",")
arr_str = arr_str.Where(Function(x) Not String.IsNullOrWhiteSpace(x)).ToArray

```

Run the two lines above in an Assign activity to create arr\_str, then

You have no choice but to loop through arr\_str using a For Each activity.  
As Yoichi advised, check that you haven’t mistakenly used the For Each Row activity and that TypeArgument is set to String.

---

<div class="post-metadata">

**Author:** ![K1111111](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@K1111111](https://forum.uipath.com/u/K1111111)\
**Post date:** [June 19, 2025, 9:40am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/9 "2025-06-19T09:40:25Z")

</div>

Thank you.  
As you pointed out, I was using ForEachRow.

---

<div class="post-metadata">

**Author:** ![K1111111](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@K1111111](https://forum.uipath.com/u/K1111111)\
**Post date:** [June 19, 2025, 9:42am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/10 "2025-06-19T09:42:15Z")

</div>

For easier maintenance going forward, we’d like the system to work so that all we need to do is add or remove the department codes listed in information.xlsx.  
At the moment, the Excel file isn’t being processed the way we’d expect…

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [June 19, 2025, 9:44am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/11 "2025-06-19T09:44:29Z")

</div>

Would the error mentioned in the subject be resolved by doing the following?

> [@Yoichi](#):
>
> I think you could try using the ForEach activity and setting TypeArgument to String.

---

<div class="post-metadata">

**Author:** ![gorby](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gorby/32/543563_2.png) [@gorby](https://forum.uipath.com/u/gorby)\
**Post date:** [June 19, 2025, 9:52am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/12 "2025-06-19T09:52:47Z")

</div>

> [@K1111111](#):
>
> At the moment, the Excel file I want to process as expected isn’t being processed,

I understand the issue.  
Did setting the argument type (TypeArgument) of the ForEach activity to String fix this issue?  
If this answer was helpful, please check Solution. 😀

---

<div class="post-metadata">

**Author:** ![K1111111](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@K1111111](https://forum.uipath.com/u/K1111111)\
**Post date:** [June 20, 2025, 1:27am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/13 "2025-06-20T01:27:25Z")

</div>

The error has been resolved!  
Thank you.

---

<div class="post-metadata">

**Author:** ![K1111111](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@K1111111](https://forum.uipath.com/u/K1111111)\
**Post date:** [June 20, 2025, 1:27am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/14 "2025-06-20T01:27:54Z")

</div>

Setting the argument type (TypeArgument) of the ForEach activity to String resolved the error.  
Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [June 23, 2025, 1:28am UTC](https://forum.uipath.com/t/string-1-system-data-datatable/2858601/15 "2025-06-23T01:28:45Z")

</div>

Closed on June 23, 2025, 1:28am UTC

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