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