How to update column's value in datatable with LINQ?

Hi, guys.

When I tried to update column’s value in a datatable by using LINQ as below.
but I got this error, any advice to solve this.

error message:
WorkProcess.xaml: Method not found: ‘Microsoft.CodeAnalysis.SyntaxTree Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.ParseText(System.String, Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions, System.String, System.Text.Encoding, System.Collections.Immutable.ImmutableDictionary`2<System.String,Microsoft.CodeAnalysis.ReportDiagnostic>, System.Threading.CancellationToken)’.

Thank you!

image

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

and I tried this method also. still got an error.

image

image

1 Like

Hi

Have a view on this expression

dt = (From r In dt.AsEnumerable
Select ia = r.ItemArray.toList
Select ic = ia.ConvertAll(Function (e) e.ToString.Trim.Replace(“old word”,“your new word”)).toArray()
Select dtCorrected.Rows.Add(ic)).CopyToDataTable()

Cheers @111962

2 Likes

@Palaniyappan
Thank you for your quick reply.
I want to update all of column(“columnname”)'s value.
how can I refer to specific column?

1 Like

Hi @111962 ,

Can you tell us the exact usecase so that we can provide you a query for that.

Thanks

1 Like

Hey @111962

Updated below.

dt = (From r In dt.AsEnumerable
Select ia = r.ItemArray.toList
Select ic = ia.ConvertAll(Function (e, index) if(dt.Columns(index).ColumnName.Equals("ColName"), e.ToString.Trim.Replace(“old word”,“your new word”), e).toArray()
Select dtCorrected.Rows.Add(ic)).CopyToDataTable()

Hope this helps

Thanks
#nK

1 Like

I’m so sorry for that I didn’t explian that clearly.

I have a datatable(Dt_PJMaster), I want to update column (“工事名1”)
I want to replace all the “,” values in the( “工事名1”) column with “、”.

Have a view on this thread with similar scenario

@111962

Hi,

The following post will help you regard of the exception in Invoke Code activity.

Regards,

1 Like

Thank you for your advice.
I tried this method, but I still can’t get rid of this error.

1 Like

Hey @111962

I hope you have created the dt variables as args for invoke code?

Thanks
#nK

I have imported this datatable argument for invoke code as belows.
image

1 Like

DtCorrected is also a new datatable that as well please.

Thanks
#nK

1 Like

Hi,

Can you try to downgrade to System.Activities package 20.10.x as refereed post in my previous post?
This matter is not the expression but InvokeCode activity itself.

Regards,

thank you for your reply.
I tried to downgrade the package( System.[Activities] package 20.10.x, but I got a lot of errors. and too many missing and invalid activities.
is there any other solution to this problem.

The Dt_PJMaster (DataTable) is defined in the xaml file, as shown in the screen scribe importing the above arguments.

Hi,

If you can share your datatable structure (column names), I might be able to provide you with expression using LoadDataRow method.

Or

Can you try to update the latest preview version (21.12.0preview) if you use stable version.

Regards,

1 Like

Thank you very much.

my datatableis like this.
I was tring to replace all the value “,” with “、” in column(工事コード).

image

Hi,

Can you try the following expression using Assign activity?

dt = dt.AsEnumerable.Select(Function(r) dt.Clone.LoadDataRow({r(0),r(1).ToString.Replace(",","、"),r(2),r(3),r(4),r(5),r(6)},False)).CopyToDataTable()

Please replace index number to column name for readability, if the above works.

Regards,

2 Likes

Thank you very much for all your advice.
However, I still can’t get rid of the error ,I will try to find another way to solve it.
Thank you very much.

Hi,

Please use it in Assign activity.

Regards,

1 Like