Display particular records

tjstewart

New member
Joined
Sep 1, 2003
Messages
3
Hi. Im trying to write my own paging functions because the DataGrid built-in paging isnt customizable enough. I want it to look a certain way, and I cant accomplish that the "easy" way. My question is how can I retrieve just records, say, 5-10 from pdf.mdb? Currently Im using this to pull db records:

Sub BindDataGrid()

Dim DSet As DataSet = New DataSet()
Dim DBConnection as OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath(DBPath))
Dim DAdapter As OleDbDataAdapter = New OleDbDataAdapter("Select * From PDF Order By ID ASC", DBConnection)
DAdapter.Fill(DSet, "PDF")

PDFList.DataSource = DSet
PDFList.DataBind()

End Sub

Can I just use a different SQL command to retrieve rows 1-5, then 5-10, 10-15 etc?

Thanks
Tj
 
Create a dataview and fill it using a datareader. A datareader allows you to read each record individually.. therefore you can stop or start whenever you want. Look up the definitions for both controls on MSDN.
 
Before I respond to this, I would like to ask if you intend to navigate forwards and backwards through your data. If the answer is yes then Im sorry but Phylums response wont work. The datareader is a one time use object, meaning that it reads your data a row at a time once, and then it is remanded to the care of the garbage collector. There are a couple of options, if you do intend a forward only read then Phylums answer is probably the best, if you intend forward and backward navigation, then I would look at getting all your data into your dataset and then cloning your datatable from the dataset into a new datatable, and using the datatable.select method to copy rows from your source table into your cloned table, then use the datatable.clear method to clear out rows you copied there when you want to move to your next "page". The one issue you face here is that if your data at its source is dynamic, then you will have to requery your source at whatever interval you determine to be satisifactory.

I hope this helps you. If you need further clarification, feel free to ask anytime.
 
Sorry, I left out a minor detail that seems obvious to me, but maybe not as a buddy of mine looking over my shoulder pointed out. You need to set your datagrids datasource to the cloned datatable.
 
Hi guys. Thanks a lot for the ideas, Ill probably put something together based on what youve suggested.

Many thanks,
Tj
 
Back
Top