Solved

Cahing a Table Adapter

Posted on 2007-12-03
2
593 Views
Last Modified: 2010-04-21
I am trying to cache a table adapter.... I've done something similar with a string, so I know I'm on the right track, but I'm just not getting the OOP of how to assign it.

I looked here, but it isn't using a tableadapter:
http://www.ondotnet.com/pub/a/dotnet/2002/12/30/cachingaspnet.html

The error I'm getting occurs the second time I hit the code AFTER it's been assigned:
Exception Details: System.InvalidCastException: Unable to cast object of type 'FeaturesDataTable' to type 'System.Data.DataSet'.
Line 102:        Dim DataGridCache As DataSet = CType(Cache.Get("DataGridCache"), DataSet)

The problem is somewhere here, I'm not assigning it a Dataset. And if I need to make it something else, I don't know what I need to make it:
Cache.Insert("DataGridCache", GridView1.DataSource, Nothing, _
                    DateTime.Now.AddSeconds(60), TimeSpan.Zero)

Someone else could probably look at this and see it in a second.

Protected Sub GetFeatureCache()
        'Programmatic Caching Setup
        Dim DataGridCache As DataSet = CType(Cache.Get("DataGridCache"), DataSet)
 
        'Check if Cache item is equal to Nothing
        If DataGridCache Is Nothing Then
            Dim IAdapter2 As New IDataSetTableAdapters.FeaturesTableAdapter()
            Dim features As IDataSet.FeaturesDataTable
            features = IAdapter2.GetFeatures
            GridView1.DataSource = features
            'insert ito cache, expire in 1 day
            Cache.Insert("DataGridCache", GridView1.DataSource, Nothing, _
                    DateTime.Now.AddSeconds(60), TimeSpan.Zero)
        Else
            GridView1.DataSource = DataGridCache
        End If

Open in new window

0
Comment
Question by:Starr Duskk
2 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 20396278
But you are assigning it as a dataset in line 3...try:

        Dim DataGridCache As DataTable = CType(Cache.Get("DataGridCache"), DataTable)
or even:
        Dim DataGridCache As IDataSet.FeaturesDataTable = CType(Cache.Get("DataGridCache"), IDataSet.FeaturesDataTable)
 

might also need:
Cache.Insert("DataGridCache", features, Nothing, _
                    DateTime.Now.AddSeconds(60), TimeSpan.Zero)
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 31412352
excellent! (second one worked)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question