in reply to How to increase the efficiency of the code wen working with DB?
Don't run 40,000 queries. Run one query that returns 40,000 rows, even if you have to loop repeatedly through those rows reading the same result-set again and again and again.