Hi Team, I have Datatable with Column Names “Name” & “Address”, I want to Update Address for name “Avinash” to “India” with the help of LinQ query, I dont want to use For Each in Datatable Activity for the above task.
I have also attached screenshot of the Datatable, Also find below Table structure in case someone Not able to access Image:
Input Datatable:
Name Address
Avinash Thane
Yogesh Kalyan
Sarita Pune
Expected Output Datatable:
Name Address
Avinash India
Yogesh Kalyan
Sarita Pune
@avinash_ghanwat1
use this in assign activity
datatablevar.rows(0).item("Address")="India"
or
datatablevar.rows(0).item(1)="India"
1 Like
ppr
(Peter Preuss)
November 28, 2023, 12:45pm
3
have a look at the different options for updating a column value
How to Update Data Column Values of a Data Table | Community Blog
As LINQ risks in such a case a more unneeded blackboxing have a look at:
2. Case: update column values on specific data rows
I know this will work, but lets say we are not sure about at which row “Avinash” name is present in datatable then what could be done?
@avinash_ghanwat1
dt.asenumerable.any(function(a) a("Name").tostring.equals("Avinash"))
gives you boolen output
gives you the row index and you can pass it in the earlier expression
dt.asenumerable.tolist.findindex(function(a) a("Name").tostring.trim.equals("Avinash"))
ppr
(Peter Preuss)
November 28, 2023, 1:02pm
6
arrIndexes | int32 Array =
(From i in Enumerable.Range(0,dtData.Rows.Count)
let v = dtData.Rows(i)("Name").toString.Trim
Where v.Equals(strYourCheckVar)
Select x = i).ToArray
with this we could retrieve all relevant row indexes
1 Like
Hi,
check this approach.
io_Input_DT.AsEnumerable().Select(y=> y).ToList().ForEach(x=>
{
if(x(“Name”).ToString() = “Your condition” )
{
x(“Name”) = x(“Name”).ToString() + " " + x(“Address”).ToString();
}
}
);
io_Input_DT.AcceptChanges();
1 Like
Thank you @Shiva_Nikhil I tried & this is working as expected.
1 Like
system
(system)
Closed
December 1, 2023, 1:07pm
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.