Sorry, there is probably an easy answer for this but I can’t figure it out.
This example will show the complete database but how do I only show the last 5 records added?
[code]// mDB is a previously connected database
Dim sql As String
sql = “SELECT * FROM Team”
Dim data As RecordSet
data = mDB.SQLSelect(sql)
If mDB.Error Then
MsgBox("DB Error: " + mDB.ErrorMessage)
Return
End If
If data <> Nil Then
While Not data.EOF
DataList.AddRow(data.IdxField(1).StringValue, data.IdxField(2).StringValue, _
data.IdxField(3).StringValue, data.IdxField(4).StringValue)
you need to be able to order the data such that the “last 5 records added” are definable. Do you have an integer primary autoincrement key for this purpose? Or a date added field?
use LIMIT and OFFSET in your sql statement to read just those 5 records.
To amend what Tim and Jean-Yves said, if you don’t order the Select statement by something, the resultant order is not reliable. Even though it seems to always list the records in a certain order, there’s no guarantee that it always will. That could come back to bite you down the road.
It’s funny Neil because I was just going to post your example. Thanks for the help, lots of my hangups are figuring out the correct syntax.
BTW, is there a reason to add the semicolon at the end? Code seems to work without it.