views:

97

answers:

1

I have set up a class as a facade to access the session variables for my app. In this app I store an entire dataset for a particular employer as a session variable.

Within one of the sub pages I have a button that adds a row to an existing table stored in that dataset.

    Dim curRow As Data.DataRow = mySession.tWorksiteOtherMeasures.NewRow()

    curRow("lngWorksiteID") = getSelectedWorksiteID(getSelectedSiteID())
    curRow("strMeasure") = ""
    curRow("lngStatusID") = -1
    curRow("lngPoints") = -1

    mySession.tWorksiteOtherMeasures.Rows.Add(curRow)

The class is accessing the table using this:

Public Shared ReadOnly Property tWorksiteOtherMeasures() As Data.DataTable
        Get
            Return dsEmployer.Tables(TWORKSITEOTHERMEASURES_IDX)
        End Get
   End Property    

Public Shared Property dsEmployer() As Data.DataSet
        Get
            Return CType(HttpContext.Current.Session(DSEMPLOYER_IDX), Data.DataSet)
        End Get
        Set(ByVal value As Data.DataSet)
            HttpContext.Current.Session(DSEMPLOYER_IDX) = value
        End Set
    End Property

When in the code to add the row the row count increments and the row exists. Once out of that scope the page refreshes due to the button being contained in an updatePanel. When that happens and I click the add button again the row counts for that item reset to 0 and 1 after the code runs. The previous added row is gone.

What am I missing? Feel free to post examples in other languages if you wish, I just happen to be using VB.NET at work. :)

Here is how the Dataset is assigned from the web service:

Public Shared Sub loadDSEmployer(ByVal strUserId As String)
    Dim myService As New someservice.service

    mySession.dsEmployer = myService.GetEmployerAndSites(strUserId, isInternal)

End Sub
A: 

I don't think one should store the dataset in a session.

For the issue at hand, I suppose calling AcceptChanges, after the row is added to the collection should help.

shahkalpesh
Unfortunately the AcceptChanges didn't work, but thanks for the response.
Brooke Jackson
As for the dataset question you have made me curious. You can chime in here, http://stackoverflow.com/questions/2336092/why-should-or-shouldnt-i-store-a-dataset-datatable-etc-as-a-session-variable-i
Brooke Jackson
How are you calling `AcceptChanges`? See an example here -> http://msdn.microsoft.com/en-us/library/system.data.datarowstate.aspx
shahkalpesh
I added mySession.tWorksiteOtherMeasures.AcceptChanges() after the added row.
Brooke Jackson
And when is `loadDSEmployer` called? On each page?
shahkalpesh