trying to cache a dataSet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I insert into the cache:
if (Cache["testQuestion"+ i] == null)
{
Cache.Insert("testQuestion"+ i, ds.Tables);
}
 
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");
 
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.
 
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

Similar Threads

trying to cache a dataSet 2
ado.net error handling 5
2 primary keys 3
Cache object expiration 4
Cache Menu 4
Cache is not work in ASP.NET 1
Cache is not available in ASP.NET 0
Cache not working as expected 1

Back
Top