trying to cache a dataSet

Discussion in 'ASP .Net' started by =?Utf-8?B?QW5kcmV3?=, Aug 19, 2005.

  1. I insert into the cache:
    if (Cache["testQuestion"+ i] == null)
    {
    Cache.Insert("testQuestion"+ i, ds.Tables);
    }
     
    =?Utf-8?B?QW5kcmV3?=, Aug 19, 2005
    #1
    1. Advertising

  2. 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");


    "Andrew" <> wrote in message
    news:...
    >I insert into the cache:
    > if (Cache["testQuestion"+ i] == null)
    > {
    > Cache.Insert("testQuestion"+ i, ds.Tables);
    > }
     
    Grant Merwitz, Aug 19, 2005
    #2
    1. Advertising

  3. 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.
     
    =?Utf-8?B?QW5kcmV3?=, Aug 19, 2005
    #3
  4. 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


    "Andrew" <> wrote in message
    news:...
    >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.
    >
     
    Grant Merwitz, Aug 19, 2005
    #4
  5. Solved the problem. Thanks.
    Mistakes like this drives me nutty.

    cheers
     
    =?Utf-8?B?QW5kcmV3?=, Aug 19, 2005
    #5
  6. hehe, but you'll never make them again


    "Andrew" <> wrote in message
    news:...
    > Solved the problem. Thanks.
    > Mistakes like this drives me nutty.
    >
    > cheers
     
    Grant Merwitz, Aug 19, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Nokes

    Cache::Cache Stale Segments

    Jeff Nokes, Sep 30, 2003, in forum: Perl
    Replies:
    0
    Views:
    608
    Jeff Nokes
    Sep 30, 2003
  2. DesignerX

    Page.Cache vs HttpContext.Current.Cache

    DesignerX, Jan 20, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    8,339
    vMike
    Jan 20, 2004
  3. =?Utf-8?B?QW5kcmV3?=

    trying to cache a dataSet

    =?Utf-8?B?QW5kcmV3?=, Aug 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    431
    =?Utf-8?B?QW5kcmV3?=
    Aug 19, 2005
  4. =?Utf-8?B?b25l?=
    Replies:
    1
    Views:
    5,345
    Karl Seguin [MVP]
    Mar 8, 2006
  5. Sergey via DotNetMonster.com

    ASP.NET Cache vs Window System Cache

    Sergey via DotNetMonster.com, Nov 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    502
    Sergey via DotNetMonster.com
    Nov 15, 2006
Loading...

Share This Page