Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 :)

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...