As already pointed out you compare all of the rows with each other. You wrote that the requirement is to compare rows only with each other but the first question is: Is the index of the row really defining the rows to compare?
What I mean is that:
- do you have the same amount of rows in both tables?
- are the rows added to the tables so that row 2 in dt is really the same thing as row 2 in dt2 and not the row 3?
Having that said, of you have the same amount of rows then simply loop through one table and fetch corresponding row. Something like:
For counter As Integer = 1 To dt.Rows.Count
Dim PTP_zakl As Date = dt.Rows(counter)(1).ToString
Dim AX_prevz As Date = dt2.Rows(counter)(1).ToString
If PTP_zakl < AX_prevz Then
sendMail()
End If
Next counter
As a side note, if the column 1 contains a date I'd use
CType
to convert the object to the date, not
ToString
and implicit conversion.
ADDITION:
If the comparison can be done based on a column to find a matching row the loop could be simplified to something like the following:
For Each dt2_row As System.Data.DataRow In dt2.Rows
If (dt.Select("Manjkajoči_MA <'" & dt2_row("Prevzeti_MA").ToString & "'").Count = 0) Then
sendMail()
End If
Next dt2_row