Solved

Cahing a Table Adapter

Posted on 2007-12-03
2
591 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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