I have some sql that works fine in access 2010 and returns the correct values. However, in VB.NET, when I run it causes the above error in the while loop. dr.HasRows is returning 'TRUE' but the var 'itm' shows nothing in auto window. Can someone please explain why this is happening and how I can correct it. Thanks
Dim cmd As OleDbCommand = New OleDbCommand("SELECT Max(Requests.[Request no]) AS [MaxOfRequest no], Requests.Customer, " &
"Max([Request Boxes].[Request no]) AS [MaxOfRequest no1], [Request Boxes].Customer " &
"FROM Requests, [Request Boxes] " &
"GROUP BY Requests.Customer, [Request Boxes].Customer " &
"HAVING (((Requests.Customer)='" & cmbCustomer.Text & "') AND (([Request Boxes].Customer)='" & cmbCustomer.Text & "')) " &
"ORDER BY Requests.Customer, [Request Boxes].Customer", oledbCnn)
dr = cmd.ExecuteReader()
If dr.HasRows Then <--- this returns true
While dr.Read
itm = CStr(dr.Item("[MaxOfRequest no]")) <--- ERROR HERE
itm2 = CStr(dr.Item("[MaxOfRequest no1]"))
End While
End If
dr.HasRowsis true means there are rows. It doesn't mean that a particular field (like[MaxOfRequest no]) is present - which the error is trying to say.