Solved

Cahing a Table Adapter

Posted on 2007-12-03
2
589 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:BobCSD
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 1

Author Closing Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now