Reputation: 3980
The following loop is driving me nuts is missing the frist record even though its not their bare in mind im a c# programmer transition Can someone help and tell me what I am doing wrong here
WriteToLogAndRaiseFeedback("Setting Department Codes Started " & Now.ToShortTimeString(), True)
Dim i As Int16
i = 0
For Each thisEntry As DataRow In findDepartmentsForGemini.Rows
i = i + 1
connection.ExecuteNonQuerySql(scriptBuilder.setGeminiDepartmentCodes(findDepartmentsForGemini.Rows(i).Item(0), findDepartmentsForGemini.Rows(i).Item(2)))
Next
WriteToLogAndRaiseFeedback("Setting Department Codes Completed" & Now.ToShortTimeString(), True)
Upvotes: 0
Views: 398
Reputation: 216303
Arrays start at index zero, so, your increment of the variable i before accessing the row, causes the skip of the first row.
However, it is not clear why you need to use this variable as indexer.
You have already the reference at the DataRow that you want to use thanks to the enumerator triggered by the foreach
For Each thisEntry As DataRow In findDepartmentsForGemini.Rows
connection.ExecuteNonQuerySql(scriptBuilder.setGeminiDepartmentCodes _
(thisEntry.Item(0), thisEntry.Item(2)))
Upvotes: 3