trying to cache a dataSet

G

Guest

I insert into the cache:
if (Cache["testQuestion"+ i] == null)
{
Cache.Insert("testQuestion"+ i, ds.Tables);
}
 
G

Grant Merwitz

Maybe the Cache["testQuestion"+ i] is not null?

try

if (Cache["testQuestion"+ i] == null)
{
Cache.Insert("testQuestion"+ i, ds.Tables);
}
else
Response.Write("CACHE IS NOT NULL");
 
G

Guest

I checked, it is not null.

I have added more code below, on how i insert and then retrieve frm the
cache. The error is not in the inserting but in the retrieving frm the cache.

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

if (Cache["testQuestion"+ i] == null)
{
Cache.Insert("testQuestion"+ i, ds.Tables)
}
else
lbl2.Text += "CACHE IS NOT NULL";

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();
}

I get the error: "Specified cast is not valid". TIA.
 
G

Grant Merwitz

yes, of course

you casting it to a dataset when it is infact a datatable

so either
Cache.Insert("testQuestion"+ i, ds)

or better yet
DataTable dt2 = (DataTable)Cache["testQuestion"+
(int)ViewState["QnNo"]];

because ds.Tables is infact a DataTable in a DataSet
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top