| There was a good tip for speeding up looping through a recordset in this tips section. (I have included it below for reference) However, if you have the option, there is another way to perform an operation on every member of a recordset that will execute much faster than any recordset operation, use a SQL UPDATE statement to modify the records. That way, the modification executes on the database server, and gets whatever optimizations your database engine provides. For example, to give all your longstanding customers a discount, you could use the following SQL statement in place of any recordset: UPDATE Customers SET Discount = 0.10 WHERE CustSince <= 1993 This could take the place of getting a recordset with the SQL: SELECT Discount FROM Customers WHERE CustSince <= 1993 and then needing to navigate the whole recordset setting each Discount to 10%. ---------------------------------------------------------------------------- ----------------------------------------------------------Accessing Databases This tip is on accessing databases. For performing an operation in every record of a Table or RecordSet (for example you could want to update some fields, or retrieve some information), generally this code is used. Do ... ... MyDynaset.MoveNext Loop Until MyDynaset.EOF Bat if you use this code Dim k As Long, j As Long MyDynaset.MoveLast j = MyDynaset.RecordCount MyDynaset.MoveFirst For k = 1 to j ... ... MyDynaset.MoveNext Next you should notice is 30% speed increase from the first code. I tried this code with a MDB file with 17000 records, and with a MDB file with 500 records. They both work well. The reason? Of course because the second code does not check the EOF condition every iteration (even if it must go to the last record and then to the first record)! Maybe, if the recordset is small you may not notice any improvement, but in this case, processing time is short anyway. I found this code does not improve processing time in Delphi. I think it's because Delphi EXE is compiled and not p-code. Tip supplied by Castelli Stefano |
Another way to speed up looping through a recordse |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design