2010-02-25 20 views
1

我已經建立了一個類作爲外觀來訪問我的應用程序的會話變量。在這個應用程序中,我將一個特定僱主的整個數據集存儲爲一個會話變量。爲什麼添加到會話數據表的行在頁面刷新時消失了?

在其中一個子頁面中,我有一個按鈕,它將一行添加到存儲在該數據集中的現有表中。

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) 

該類訪問使用該表:

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 

當在代碼中加入該行的行計數增量和行存在。一旦超出該範圍,由於按鈕包含在updatePanel中,頁面將刷新。當發生這種情況時,我再次點擊添加按鈕,在該代碼運行後,該項目的行計數重置爲0和1。之前添加的行不見了。

我錯過了什麼?如果你願意,隨意發佈其他語言的例子,我只是碰巧在工作中使用VB.NET。 :)

這裏是如何的數據集從網絡服務分配:

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

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

End Sub 
+0

查看最初如何在會話中存儲對象可能會有幫助。你能告訴我們mySession的代碼嗎? – 2010-02-25 17:38:53

+0

好的,添加到底部。 – 2010-02-25 17:48:55

回答

0

我不認爲一個人應該在數據集中存儲在一個會話做。

對於手頭上的問題,我想打電話給AcceptChanges,行被添加到集合後應該有所幫助。

+0

不幸的是,AcceptChanges不起作用,但感謝回覆。 – 2010-02-25 17:13:16

+0

至於數據集問題,你讓我好奇。你可以在這裏,請參閱http://stackoverflow.com/questions/2336092/why-should-or-shouldnt-i-store-a-dataset-datatable-etc-as-a-session-variable-i – 2010-02-25 17:25:26

+0

你叫'AcceptChanges'?看到這裏的一個例子 - > http://msdn.microsoft.com/en-us/library/system.data.datarowstate.aspx – shahkalpesh 2010-02-25 17:40:32

相關問題