Why is a row added to session datatable disappearing on refresh of page?
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
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.
精彩评论