SQL QueryToClass syntax


Recommended Posts

I've been successful using the QueryToClass for accessing single SQL server recordsets, but I don't see any documentation for traversing records such as EOF and MoveNext functions. I've tried rst.MoveNext() but that doesn't seem to work. Please help.

Link to comment
Share on other sites

QueryToClass doesn't generate a recordset that you can traverse using those functions. It instead downloads the entire query result into the class that it generates. You can then work your way through the records by simply indexing the variables. So:

private myclass = querytoclass(...)
for (private i = 0, i < myclass.RecordCount, i++)
   ? "Record dump: " + myclass.firstfield[i] + ", " + myclass.secondfield[i]

This method, by the way, is much, much, much faster than using straight Query() and then cycling through using MoveNext(), etc. It also allows you to randomly access your records even if your database is forward only. Just watch out for memory, since the entire query result is loaded into memory.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.