For Each row As DataRow In dt1.AsEnumerable
If CInt(row(0).ToString).Equals(CInt(row(1).ToString)) Then
row(2)=“equal”
Else
If CInt(row(0).ToString)<(CInt(row(1).ToString)) Then
row(2)=row(0).ToString
Else
row(2)=row(1).ToString
End If
End If
Next
I have replicated your use case and below is the xaml file for your reference Compare Dt.zip (11.3 KB)
below is the output screenshot
Below is the linq
(From row In dt.AsEnumerable
Let column1Value = If(row("Column1") IsNot DBNull.Value AndAlso Not String.IsNullOrEmpty(row("Column1").ToString), CInt(row("Column1")), 0)
Let column2Value = If(row("Column2") IsNot DBNull.Value AndAlso Not String.IsNullOrEmpty(row("Column2").ToString), CInt(row("Column2")), 0)
Let a = Math.Min(column1Value, column2Value)
Select dt.Clone.Rows.Add(column1Value.ToString, column2Value.ToString, a.ToString)).CopyToDataTable
For Each row As DataRow In dt1.AsEnumerable
Dim value1 As String = row(0).ToString()
Dim value2 As String = row(1).ToString()
If String.IsNullOrEmpty(value1) And Not String.IsNullOrEmpty(value2) Then
row(2) = value2
ElseIf Not String.IsNullOrEmpty(value1) And String.IsNullOrEmpty(value2) Then
row(2) = value1
ElseIf Not String.IsNullOrEmpty(value1) And Not String.IsNullOrEmpty(value2) Then
If CInt(value1) = CInt(value2) Then
row(2) = "equal"
ElseIf CInt(value1) < CInt(value2) Then
row(2) = value1
Else
row(2) = value2
End If
Else
row(2) = "Both Empty or Null"
End If