Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
Thanks in advance

Can any body explain the which is best way writing code in my scenario

I have data base with some tables, I have to show data from the database in pages (contains 20 rows in each page) i am doing my app is - iam retrieving the data from data by 20 rows each and every time for showing in a each page using SP, every page click i connected to sql and showing data in to Front End Page.

My idea is - to get complete data in to datatable in one single Query execution(single iteration) and store the data in session and use it in every page click.

Is this way is Correct or not?

and which is best way to get the data of every page click .

Thanks inadvance once again.
Posted

Don't put Data in to Session. Large amount data can reduce the performance of application. I want to give a suggestion that

1. You retrieve 100 records from data base in single interaction with Database.
2. You put these records in cache.
3. Show data from cache means retrieve 20 record from the cache on grid.
4. When you reach on page number 6,11,16...then again fetch next 100 records and update cache with new records.

Thanks,
Sandeep
 
Share this answer
 
Not the way to go.
Think of it this way. Paging is there to make the application more responsive and the display easier to digest for the user.
If you have a couple million records of data and you retrieve it all at once then you will create an extensive performance issue not to mention using a ridiculously large session object.
The proper way to do this would be to select only the page of data you want on each successive call to the server.
 
Share this answer
 
Comments
woopsydoozy 15-Aug-13 14:31pm    
eh, OK, yes, depends on the size of the data. If your datasets are large, paging on the DB server is the way to go. Anything under ... say (SWAG) 10K records? Get the whole thing and go for it.
fjdiewornncalwe 15-Aug-13 14:46pm    
I disagree. I don't think there is ever a good case for processing data not required regardless of the data volume.
Yes, your explanation is correct. You add some data container to your page (say a gridview), get a large dataset (say a table), and set the datasource of the control to the dataset. You can cache your dataset in ViewState or Session depending on whether it is applicable to only your page, or your whole application. You configure paging on the control, and handle the page events to reset which subset page of the whole dataset to display.

Not a complete example, but to highlight the important pieces:
PAGE:
ASP.NET
<asp:gridview id="gvData" runat="server" allowpaging="true" pagesize="20"></asp:gridview>


CODE:
VB
Private Sub gvData_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvData.PageIndexChanging
    gvData.PageIndex = e.NewPageIndex
    gvData.DataSource = ViewState(DATA_NAME)
    gvData.DataBind
End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900