Change column value using LINQ

Hi All,
I need to change the one value in particular column using LINQ query

Input
22-
34-
35-
26-
46-

Output
-22
-34
-35
-26
-46

The output should be an Data Table type. Help me on this

Regards,
Kaviyarasu N

@Kaviyarasu_N
DT.AsEnumerable.Tolist.Foreach(Sub(r) r(“columnname”)=“-”+r(“columnname”).tostring.replace(“-”,“”)).Copytodatatable

HI @Kaviyarasu_N

How about this LINQ expression

DtBuild.AsEnumerable.Select(Function(r) DtBuild.Clone.LoadDataRow({System.Text.RegularExpressions.Regex.Replace("-"+r("Column 1").ToString,"\W$",""),r("Column 2"),r("Column 3")},False)).CopyToDataTable

Check out the XAML file

Find&Replace.xaml (9.1 KB)

image

Regards
Gokul

Hi @Kaviyarasu_N ,

Do you want the output numbers to be negative?

Kind Regards,
Ashwin A.K

Hi @sangeethaneelavannan1

I am getting an error

image

Hi @Kaviyarasu_N

You can use an invoke code activity for the same

dtout.AsEnumerable.ToList.ForEach(Sub(row)
   row("ColumnName")="-"+row("ColumnName").ToString.Replace("-","")
End Sub
)

Thanks

Try below @Kaviyarasu_N

Use Invoke Code
Edit Arguments, Datatable should be I/O direction

dtSample.AsEnumerable.Where(Function(row) row(“Column1”).ToString.EndsWith(“-”)).ToList().ForEach(Sub(row) row(“Column1”) = "-"+row("Column1").Tostring.split("-"c)(0))

Above expression will take the values which ends with - and then manipulate

Hope this may help you

Thanks,
Srini

Use this code inside invoke code activity and see

Hi All,
Thanks for your answers. I want the code for this. Please check in below

Input
22-
34
-35
26-
-46

Output
-22
-34
-35
-26
-46

Regards
kaviyarasu N

Hi @Kaviyarasu_N

Checkout this expression

(From D In Dt1.AsEnumerable
Let i= System.Text.RegularExpressions.Regex.Replace(d(0).ToString,"\d+","").ToString+System.Text.RegularExpressions.Regex.Match(d(0).ToString,"\d+").ToString
Select Dt2.Rows.Add(i)).CopyToDataTable

image

Regards
Sudharsan

Have you checked this XAML file? @Kaviyarasu_N

Works with the input you shared too @Kaviyarasu_N
image

Regards
Sudharsan

HI @Sudharsan_Ka @Gokul001 @Srini84
I want code for this. The output must be as datatable. Please share screenshots if possible.

Note: Use assign activity for LINQ query

Thanks!!!

Output is datatable @Kaviyarasu_N

image
image

Regards
Sudharsan

Hi @Kaviyarasu_N

How about this LINQ expression

DtBuild.AsEnumerable.Select(Function(r) DtBuild.Clone.LoadDataRow({"-"+System.Text.RegularExpressions.Regex.Replace(r("Column 1").ToString,"\W","")},False)).CopyToDataTable

Check out the XAML file

Find&Replace.xaml (9.0 KB)

image

Regards
Gokul

Thank you all for quick responses :heart_eyes:

1 Like

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