trying to cache a dataSet

G

Guest

I hope this doesn't sound too silly. I am trying to cache a datatSet. I have
written the code below.

I insert into the cache:
Eg. i = 1.

if (Cache["testQuestion"+ i] == null)
{
Cache.Insert("testQuestion"+ i, ds.Tables);
}

retrieve from the cache:

DataSet ds2 = (DataSet)Cache["testQuestion"+ (int)ViewState["QnNo"]];
if (ds2 != null)
{
ds2 = (DataSet)Cache["testQuestion"+ (int)ViewState["QnNo"]];
MyRepeater.DataSource = ds.Tables[(int)ViewState["QnNo"]];
MyRepeater.DataBind();
}

Is there a problem there ?
TIA.
 
G

Guest

Hi,
I agree to what Grant is saying. Please try this out.

if (Cache["testQuestion"+ i] == null)
{
Cache.Insert("testQuestion"+ i, ds.Tables);
}

retrieve from the cache:

DataTable dt2 = (DataTable)Cache["testQuestion"+ (int)ViewState["QnNo"]];
if (dt2 != null)
{
dt2 = (DataTable)Cache["testQuestion"+ (int)ViewState["QnNo"]];
MyRepeater.DataSource = dt2;
MyRepeater.DataBind();
}

All i have done here is modified your original code little bit. And Please
be assured that it wont bother your logic of accessing exactly that number of
table in the original dataset that you have implemented by using "i". :)

Hoping a thanks as it is going to work out perfectly.
 

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,770
Messages
2,569,585
Members
45,080
Latest member
mikkipirss

Latest Threads

Top