Solved

Cahing a Table Adapter

Posted on 2007-12-03
2
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Suggested Solutions

Title # Comments Views Activity
reading excel file in .net 2 44
orderby list (from Json) 1 42
asp.net web app 3 54
How does GeoJson relates to Leaflet and Mapbox? 4 43
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…

738 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