Caching a dataset..

S

Scott M.

I'd like to persist a DataSet between page calls.

Can someone give me specific code (VB.NET) examples of doing this using
ViewState as well as an example using the Application Cache (I know how to
get the DataSet, so please pick the example up from there)?

Thank you in advance!
 
K

Kevin Yu [MSFT]

Hi Scott,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to pass a DataSet object
between pages in an ASP.NET application. If there is any misunderstanding,
please feel free to let me know.

As far as I know, in this case, the best way of passing objects between
page calls is to use HttpSessionState. It stores that object in server's
memory and we can get that object in another page. As HttpSessionState is
independent from each request, we needn't worry about the case that multple
user are accessing it. Here is a code snippet I have written for your
reference:

Dim ds As New DataSet 'The following codes saves the DataSet
to a Session.
Session("data") = ds

If Session("data") <> Nothing Then 'We can get the DataSet
in another page with the following code.
ds = Session("data")
Session.Remove("data") 'After using the Session, we have
to remove it to release memory.
End If

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
S

Scott M.

Thank you Kevin, but in my original post I was asking for examples of
storing a DataSet in the Cache as well as ViewState, not the Session.

Could you provide examples of this? Does the DataSet need to be
serialized/deserialized?
 
K

Kevin Yu [MSFT]

Hi Scott,

We have posted a reply in another thread in
microsoft.public.dotnet.framework.aspnet. Please check it in that thread.
Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
C

Cor

Hi Kevin,
We have posted a reply in another thread in
microsoft.public.dotnet.framework.aspnet. Please check it in that thread.
Thanks!

I was following this thread, can you post it in this newsgroup also I have
searched in the ASPNET newsgroup, but there was no message from you as as
far I could see the last 14 days.


Cor
 
S

Scott M.

Hey Cor,

Here it is, in a nutshell (assume a populated DataSet called "ds" already
exists):

'To store the DataSet in ViewState
ViewState.Add("myData", ds)

'To retrieve the DataSet from ViewState
Dim x as DataSet = CType(ViewState.Item("myData"), DataSet)

---------------------------

'To store the DataSet in the Cache
Cache.Insert("myData", ds)

'To retrieve the DataSet from Cache
Dim x as DataSet = CType(Cache.Item("myData"), DataSet)
 
K

Kevin Yu [MSFT]

Thanks Scott for sharing your experience with us!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
C

Cor

Hi Scott,

Thank you, however in the way you show it to me, it looks to me a little bit
as an alternative operation for persisting dataset between pages and I
assume that is it not.

In my opinion are there three different operations. The viewstate belongs to
the page, the session to the session from the client and the cache to the
application.

The viewstate and session are good described, so about that I have no
questions.

With the cache it is a different, this is the only (more than some lines)
documentation I have from the cache.

http://www.dotnetjunkies.com/quickstart/aspplus/doc/cachingoverview.aspx

According to this, I think that a dataset in a cache belongs to all users to
an application and not to one client. (By instance an article dataset to
have as reference for an hour in memory to speed up).

Therefore, to use the words from your question, that means in my opinion
that using the dataset in a cache is persisting data between clients and not
between only pages.

However, although that is what I think these pages tell me, I would like to
have piece of documentation where that is more explicitly told, and
therefore I was following this thread.

Cor
 
S

Scott M.

Cor,

You are correct that the viewstate persists the stored item between calls to
the same page, while the cache persists items between any application
resource. But, it can be said the if something is stored in the cache, it
will in fact persist between page calls. This was my original need, to
store a DataSet between two page calls. I just wanted to see it done in 2
different ways.
 
C

Cor

Hi Scott,

Read it again.

Are you sure you want a persistent dataset which is readed in the morning
and stays the same till the end of the evening.

I think than that the cache is the right one. But every client gets the same
as far as I can see. However I am still not sure of it (I never tested it)
and therefore I was folowing this thread.

When you want a dataset connected to pages from one client, use the session
when it are different pages in my opinion.

Cor
 
C

Cor

Hi Scott

I see that I forgot to write about that two different ways, it are not thow
different ways, it are in my opinion two different things to hold data.

The same as a house and a car are two different things although you can sit
inside both.

Cor
 
S

Scott M.

I understand the difference between page state and application state. That
was never part of my question. I was interested in seeing the code on how
to persist a DataSet in ViewState as well as the Cache, not to understand
why or when (which I already have an understanding of).
 

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

Similar Threads

Datasets fundamental 5
Session or Cache(ing) of DataSet? 1
Designing a Dataset 1
Newbie: locking disconnected datasets 1
Caches, Datasets, and Relations 1
ASP.NET with Datasets 4
Simple ADO tasks 2
XML Dataset 2

Top