Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 13th, 2007, 05:57 PM
Authorized User
Join Date: Sep 2007
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Filtering Data after its been cached

I have a web app that contains 5 listboxes with data that is loaded on page_load. In trying to develop a web app that has increased performance by keeping frequently accessed or expensive data in memory rather than relying on repeated database calls, I've created dataSet caches for each listbox. An example of one of the caches is given below:

     Public Sub LoadDistrictData(ByVal e As String)
      If Cache("Dist") Is Nothing Then
         Dim dsDist As New DataSet
         dsDist = getDistrict()
         Cache.Insert("Dist", dsDist, Nothing, DateTime.Now.AddMinutes(10), Nothing)
      End If

      Dim dvDistrict As New DataView(Cache("Dist").Tables(0))
      lstDistrict.DataSource = dvDistrict
      lstDistrict.DataValueField = "Distrc"
      lstDistrict.DataTextField = "cDistrict" '"DIDSNM"
   End Sub

    Function getDistrict() As DataSet
      Dim dsDist As New DataSet
      If Cache("Dist") Is Nothing Then
         Dim daDistrict As New SqlDataAdapter("sp_SelectDistrict2", sqlConnWhere)
         daDistrict.SelectCommand.CommandType = CommandType.StoredProcedure
         Dim workParam2 As SqlParameter = Nothing
         workParam2 = New SqlParameter("@regID", System.Data.SqlDbType.VarChar)
         workParam2.Direction = ParameterDirection.Input
         workParam2.Value = ViewState("Region")
         daDistrict.SelectCommand.Parameters.Add(workParam2 )
         Catch ex As Exception
            lblInfo.Text = "Database error: " & ex.Message
            Exit Function
         End Try
         Cache.Insert("Dist", dsDist, Nothing, DateTime.Now.AddMinutes(10), Nothing)
      End If
      Return Cache("Dist")
   End Function

    Private Sub lstDistrict_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstDistrict.SelectedIndexChanged
      Dim x As Integer
      Dim distsel As Integer = 0
      Dim dstval As String
      For x = 0 To lstDistrict.Items.Count - 1
         If lstDistrict.Items(x).Selected = True Then
            dstval = dstval + Convert.ToString(lstDistrict.Items(x).Value)
            distsel = distsel + 1
         End If
      ViewState("distsel") = distsel
      ViewState("Territory") = dstval
      ......other subs
   End Sub

Both the data and cache load correctly. However, a selection in one listbox (the first listbox) is suppose to filters data in the remaining 4 listboxes. But since my cache is not equal to NOTHING then the updated ViewState("Region") (created on SelectedIndexChange of the first listbox) is not used as the parameter which will filter the remaining listboxes. Instead the previous Cache is used. I could set the cache equal to NOTHING or Cache.Remove("Dist") on selectedindexchange, but that would require a hit to the server again (which is what I'm trying to avoid). Is there a way to FILTER the EXISTING dataSet Cache? I guess I'm going about this the wrong way. Any help would be greatly appreciated.


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering XML data aldwinenriquez XSLT 7 August 25th, 2008 03:24 AM
data filtering from combobox MAKO C# 4 June 1st, 2006 03:54 AM
Filtering User data donydog Classic ASP Databases 0 February 6th, 2006 09:33 PM
Need Help on Filtering duplicated data fanyin XSLT 2 November 4th, 2004 08:06 PM
Filtering data by code rodrigoss BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 June 23rd, 2004 02:06 PM

All times are GMT -4. The time now is 08:18 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.