Wednesday, February 27, 2013

ASP.net : Issues using application variables to hold common LOVS from database in memory.

The dissappearing dropdown values:
 
The shipvia dropdown on our billing/shipping page had a list of values pulled from the database.

In order to limit roundtrips to the database...I put the dataset in an application variable based on business unit, active shipto, inactive shipto.....causing a number of application variables to be created.  
f.e. 
     application ("BUSUNIT1_BILLSHIP_LOVS_A")
     application ("BUSUNIT2_BILLSHIP_LOVS_I")
...

All worked well until we started having to find a specific value from that dataset.
We wanted to find the value of a particular shipto in the dataset and return its number.

Getting the number worked fine, however, when we went back to the billing/shipping page and noticed our dropdown only had 1 value left in the set.  The value we had just searched for.

To create our application variable we used:

     Public Shared Function populate_billship_lovs(business_unit As String , active_flag As String ) As DataSet
        Dim context As HttpContext
        Dim application As HttpApplicationState
        Dim g As New General
        '**********************************************************
        ' Get current context and application
        '**********************************************************
        context = HttpContext .Current
        application = context.Application
        Dim ds As DataSet
        Dim coll As New Collection
        If active_flag <> "A" Then
            active_flag = ""
        End If
        If application(business_unit + "_BILLSHIP_LOVS_" + active_flag) Is Nothing Then
            'Get all other LOVs from Sample DB
            Dim cl As New Collection
            cl.Add( "SHIP_VIA" )
            ds = g.GetLOVValues(business_unit, active_flag, cl)
            application(business_unit + "_BILLSHIP_LOVS_" + active_flag) = ds
        Else
            ds = CType (application(business_unit + "_BILLSHIP_LOVS_" + active_flag), DataSet )
        End If
        Return ds
    End Function

This populates 2 lists of of values from the database the first time....on consequent calls, it sees there's a application variable and returns the dataset it has in it.

The code that screwed it up
     Public Shared Function findshipvia(via As String , busunit As String, active_flag AsString ) As String
        Dim ds As New DataSet
        Dim context As HttpContext
        Dim application As HttpApplicationState
        Dim g As New General
        '**********************************************************
        ' Get current context and application
        '**********************************************************
        context = HttpContext .Current
        application = context.Application
        ds = g.populate_billship_lovs(busunit.ToUpper, active_flag)
            Try
            'ds = CType(application(busunit.ToUpper + "_BILLSHIP_LOVS_" + active_flag), DataSet)
            Dim dv As New DataView
                dv = ds.Tables("SHIP_VIA" ).defaultview
                dv.RowFilter = "LOV_VALUE=" + Spublic .dbwrite(via)
                dv.RowStateFilter = DataViewRowState .CurrentRows
                Dim RESULT As String
                RESULT = dv.Item(0).Item(0).ToString
                Return RESULT
            Catch ex As Exception
                Return Nothing
            End Try
    End Function

Setting the dv variable to the .defaultview of the datatable, it caused the defaultview to be filtered and only return the one row.
I had not expected this to happen, I thought the dv variable would live only in the scope of this call...not affect the dataset kept by the application variable.

To fix this, I had to remove the .defaultview and assign the datatable. 
I'm still not sure why this works this way.

     Public Shared Function findshipvia(via As String , busunit As String, active_flag AsString ) As String
        Dim ds As New DataSet
        Dim context As HttpContext
        Dim application As HttpApplicationState
        Dim g As New General
        '**********************************************************
        ' Get current context and application
        '**********************************************************
        context = HttpContext .Current
        application = context.Application
        ds = g.populate_billship_lovs(busunit.ToUpper, active_flag)
            Try
            'ds = CType(application(busunit.ToUpper + "_BILLSHIP_LOVS_" + active_flag), DataSet)
            Dim dv As New DataView (ds.Tables("SHIP_VIA" ))
                dv.RowFilter = "LOV_VALUE=" + Spublic .dbwrite(via)
                dv.RowStateFilter = DataViewRowState .CurrentRows
                Dim RESULT As String
                RESULT = dv.Item(0).Item(0).ToString
                Return RESULT
            Catch ex As Exception
                Return Nothing
            End Try
    End Function

Sunday, March 23, 2008

It's Official: Hulu Opens Up on Wednesday March 12, 2008

No one can say they didn't see this one coming: Hulu will finally open up to the public this week, on Wednesday to be precise and yes, it's official. The company's been in private beta for 4.5 months. If you haven't managed to snag one of the many invitations floating around, Hulu's a remarkable online video service despite its shortcoming.

read more | digg story

Monday, February 11, 2008

Ginormous 'Blue Screen of Death' Hits Las Vegas

Don't feel bad when you get infamous 'Blue Screen of Death' on your PC. It happens in Vegas too. Here's proof that not everything that happens in Vegas stays in Vegas. This is a picture of the Paris Hotel marqui in Las Vegas snapped by a vacationer. Photos show they finally got the system booted by morning, but it was not much of an improvement.

read more | digg story

Monday, April 12, 2004

Seems like a good place to put down on my junk code that doesn't fit in my brain!