Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cahing a Table Adapter

Posted on 2007-12-03
2
Medium Priority
?
598 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 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