As I expected (and as documentation states - which I followed), invoking .NextRow moves the cursor position 1 down row of resultset.
So, if the
NEXT call to .NextRow had only one row in Cursor/resultset to begin with - It Returns False! (we consumed 1 row in first call (moving it by one).
Your suggestion failed. Try it yourself.
If resultset returned many rows, this will work.. If rs returns only 1 row - you will suck air...
Sub UpDateZone(txt As String)
Dim q As String
Dim tbl As String
Dim Cursor As ResultSet
Dim res As String = "Not Found!"
If txt = "" Then
lblzone.Text = res
Return
End If
If rbcan.Checked Then
tbl = "postal_codes"
q = "Select * from "&tbl&" where postal_code LIKE ('"&txt&"%')"
Cursor = SQL2.ExecQuery(q)
Else
tbl = "zip_codes"
q = "Select * from "&tbl&" where postal_code LIKE ('"&txt&"%')"
Cursor = SQL3.ExecQuery(q)
End If
' your suggestion...
Private nextRecord As Boolean = Cursor.NextRow ' this will move cursor 1 row - as stated (wishing we had a rowcount across all platforms - but not yet)
If Not(nextRecord) Then
Log("no records")
Else if nextRecord Then
Log("We had (at least 1 record in result - no way to determine how many...")
Do While Cursor.NextRow
res = Cursor.GetString("place_name")&", "&Cursor.GetString("acode1")&CRLF&Cursor.GetString("aname2")
Log("We have a record to set - exit loop ")
Exit
Loop
' Log("Should be records - but if only one existed ... we skipped the only record found already!!!!")
End If
Cursor.Close
lblzone.Text = res
End Sub
Please explain where I going wrong. "
No" is not definitive as a conclusive explanation, as I understand it the issue.
PS:
The call to HasRecords (providing it is a simple statement) has no effect (delay) on the system. Result is returned in under 1 ms. Works for me.
Thanks