dt1=(From row In dt1.AsEnumerable()
Let A=row(“Column_A”)
Let B=If(dt2.AsEnumerable().Any(Function(r) r(“Master_A”).ToString = row(“Column_A”).ToString), “NIL”, “NA”)
Select dt1.Clone.Rows.Add(A,B)).CopyToDataTable()
I have 2 data tables. One data table has receipting status column
receipting status is updated with certain data however sometimes bot is not updating it properly
3)so in that condition I need to match 2 data tables with certain column name then where receipting status row is blank it should update it as NIL
Pls modify this above Linq query as I am not good in this.
Could you maybe provide us with the Sample Input data and it’s Expected Output data ?
The, Linq Query used, has two columns to be compared but it looks like from the Statement provided you would require to compare another column value, once the initial column comparison is done.
The Input and Expected Output data would allow us to infer some things and deduce the logic, which would help in providing suggestions/solutions faster.
For Each row As DataRow In dt1.Rows
Dim columnAValue As Object = row(“Column_A”)
Dim receiptingStatusValue As Object = row(“Receipting_Status”)
' Check if the receipting status is blank or empty
If String.IsNullOrEmpty(receiptingStatusValue.ToString()) Then
' Search for a matching row in dt2
Dim matchingRow As DataRow = dt2.AsEnumerable().FirstOrDefault(Function(r) r("Master_A").ToString() = columnAValue.ToString())
' Set the receipting status based on whether a match was found
Dim receiptingStatus As Object = If(matchingRow IsNot Nothing, "NIL", "NA")
' Add a new row to the result table with the updated receipting status