How to store a datatable temporarily

S

Sobin Thomas

Hi All.......
I am a beginner in asp.net.I need your help.I have a gridview control in my
Default.aspx page.I use data adapter to fill a datatable and then I set the
datasource of the gridview as the datatable.The datatable obtained is a
large one.I want this table to be in memory(I dont know how to),as I have to
use the same datatable for enabling paging in gridview.
In short,my problem is ,I need to store the datatable (which is filled by
the adapetr) somewhere temporarily for further use.How can I accomplish
this?
Hope You'll surely have the solution
Regards
 
M

Michael Nemtsev [MVP]

Hello Sobin,

First, if you get everything from DB to DataSet/DataTable in will be stored
in memory.
Second, your should not extract everything from DB to you dataTables, because
it hinders the performance
Third, read there http://msdn.microsoft.com/en-us/library/aa479347.aspx how
to implement paging without extracting all data from database

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


ST> Hi All.......
ST> I am a beginner in asp.net.I need your help.I have a gridview
ST> control in my
ST> Default.aspx page.I use data adapter to fill a datatable and then I
ST> set the
ST> datasource of the gridview as the datatable.The datatable obtained
ST> is a
ST> large one.I want this table to be in memory(I dont know how to),as I
ST> have to
ST> use the same datatable for enabling paging in gridview.
ST> In short,my problem is ,I need to store the datatable (which is
ST> filled by
ST> the adapetr) somewhere temporarily for further use.How can I
ST> accomplish
ST> this?
ST> Hope You'll surely have the solution
ST> Regards
 
C

Cowboy \(Gregory A. Beamer\)

ASP.NET provides a few methods of storing data:

ViewState - ie, in the page. Not good for a large amount of data
Cache - Application caching
Session - Per user caching

If you are paging small amounts of data, you can either pull it each trip or
cache in ViewState. Once you start getting more data, you will want to use
Cache or Session. Session is useful if the user is getting data you are
unlikely to pull for other users. If they are examining the same data sets,
you are better to use Cache.

A bit of info:

Caching:
http://www.eggheadcafe.com/articles/20060407.asp
Go down to caching application data for a code sample

More specific Caching implementation
Part I http://geekswithblogs.net/ranganh/archive/2005/12/28/64260.aspx
Part II http://geekswithblogs.net/ranganh/archive/2005/12/28/64300.aspx


ViewState - more an intro to how it works
http://msdn.microsoft.com/en-us/library/ms972976.aspx

Session - also general
http://msdn.microsoft.com/en-us/library/ms972429.aspx

In general, you load the data in one of two places:

1. Page_Load in a block where IsPostBack is false
2. After a form submit to pull data

Either way, you isolate this so this code is not run on every hit to the
page. If not, your paging will never work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top