SIMIN Posted July 29, 2008 Posted July 29, 2008 Hello, I use this code to loop through all items and read all of them, from 1st item to the last one! Dim ReadUsers As New OleDb.OleDbCommand("SELECT * FROM Emails WHERE GroupID = '" + MyID + "'" + SortSQL, MyConnections) Dim MyReader1 As OleDbDataReader = ReadUsers.ExecuteReader While MyReader1.Read ... End While This is OK when I want to read all items of this table. But what should I do if I want to read only item number 100 to 200? I mean in the above code how can I change the While loop to a For loop with specified start and end point? Thank you for helping :) Quote
Administrators PlausiblyDamp Posted July 29, 2008 Administrators Posted July 29, 2008 DataReaders are designed to be accessed in a sequential manner, there is no way to skip to a certain row without reading all the rows before it. Personally I would change the select statement to just bring back the rows I am interested in rather than all rows. You might alslo want to look at parameterising the query as building a string that way can open you up to security risks. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
SIMIN Posted July 29, 2008 Author Posted July 29, 2008 Thanks, you know there's a problem, my real database has around 10.000 records. When I want to read all of records, there's no problem. But for example, if I want to read the last 1000 records, from 9001 to 10.000, there will be a long delay if I want to read the firs 9.000 records and just skip them / continue while... What other way do you recommend? Quote
Administrators PlausiblyDamp Posted July 29, 2008 Administrators Posted July 29, 2008 Do the records have a sequential identifier or similar? How would you normally identify which record you want to start at? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
SIMIN Posted July 29, 2008 Author Posted July 29, 2008 User specify that for example he wants to read from record #1 to #100 OR from #1000 to #1500 Quote
Administrators PlausiblyDamp Posted July 30, 2008 Administrators Posted July 30, 2008 Do these numbers match up with a particular field or would they simply be based on the data returned? Out of interest what database are you using? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.