Re: [問題] 網路常斷線與session儲存的資料

看板Web_Design作者 (thinkfun)時間15年前 (2010/10/21 12:38), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/7 (看更多)
※ 引述《opoepev (opoepev)》之銘言: : ※ 引述《thinkfun (thinkfun)》之銘言: : : Protected Sub Button1_Click(ByVal sender As Object, ByVal e As : : System.EventArgs) : : Dim selectedid As Integer, InsertCommandString, UserInput, Product, Addr As : : String, P_Type As Integer : : Dim Blist() As String ={"a","b","c","d"} : : DClist() As String ={"e","f","g","h"} : : selectedid = Application("counter1") : : pname = Session("P_name") : : Addr = Request.Cookies("Addr").Value : : UserInput = "ignore" : : 12 If Session("Product") <> 0 Then : : 13 Product = DClist(pname) : : 14 P_Type = Session("Product") : : 15 Else : : 16 Product = Blist(pname) : : 17 P_Type = Session("Product") : : 18 End If : : SqlDataSource1.SelectCommand = "SELECT * FROM [Q1] where id=" & : : selectedid : : GridView1.DataBind() : : 21 If CInt(GridView1.Rows.Count.ToString()) <= 0 Then : GridView.Rows.Count本身就是Integer了~不用ToString再CInt... : : '因為寫入資料庫的部分有成功寫入過,所以我略過InsertCommandString的設定 : : 22 SqlDataSource1.InsertCommand = InsertCommandString : : SqlDataSource1.Insert() : : Response.Redirect("./Personal.aspx") : : Else : : Response.Redirect("./Personal.aspx") : : End If : : End Sub : 先確定幾個問題... : 1.Session("P_name")的值是什麼? : 2.Session("Product")的值是什麼? : 其實感覺你想得到的東西是... : Product設定為DClist或Blist中的某個值 : 然後P_type=Product,Session("Product")=pname 是的,就如你所說的,只是想儲存這兩筆資料, : 不過感覺你的selectedid可能有點問題~ 非常感謝,我剛剛查了一下,發現Application 有下面的問題 Application物件的生命有限,預設超過20分鐘無人連線,或web伺服器重新啟動後, Application物件就會被清除。 1. 依據上述,儘管已經連上網站,是否只要沒有更改Application("counter1")的動作 Application("counter1")就會自動清除? 導致取得的Application("counter1") 為空值? 或是回復至原來的值? 因為我在使用者進入網站時,Application("counter1")會加1 後面則僅讀取Application("counter1")的值, 如果我把Application 的值儲存到Session("counter1")是否就不會有問題了? 用Session("counter1")傳遞,session.timeout設定為300 是否可行? 2. 關於Application("counter1"),我在下面的寫法, 有可能讓多人取得同一個Application值嗎? 尤其是在由文字檔中取得數字上,如果A進入網站後,文字檔中取得的數值10 Application("counter1") 為 11,在A還沒離開網站前, B進來了,B取得的Application("counter1") 也會是11嗎? 或是12? 在一開始的網頁中,有下面的程式碼 Application.Lock() Application("counter1") = Application("counter1") + 1 Application.UnLock() 同時在Global.asax 有下面的設定 '應用程式開啟時執行的程式碼,由文字檔中取得數字 Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) Application("counter1") = My.Computer.FileSystem.ReadAllText(FILE_COUNTER) End Sub '應用程式關閉時執行的程式碼 Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) If Not Application("counter1") Is Nothing Then My.Computer.FileSystem.WriteAllText(FILE_COUNTER, _ Application("counter1"), False) End If End Sub : Debug一下,在 : SqlDataSource1.SelectCommand = "SELECT * FROM [Q1] where id=" & selectedid 後 : 加入 : Response.Write("SELECT * FROM [Q1] where id=" & selectedid.ToString()) : 確定你的SqlDataSource1沒有問題... : 不過講這麼多好像和你的情況沒有什麼關係 = =" : 因為你目前是感覺沒有寫入資料~ : 而前面說的那些...好像都不會影響到你寫資料的問題... : 除了selectedid之外...其他的沒什麼關係! : 建議你可以 : 在 If Cint(GridVies1.Rows.Count.ToString()) <=0 之下加入 : Respose.Write("InsertValue") : 在 Else 之下加入 : Response.Write("NotInsert") : 然後去看看到底有沒有進到整個寫入的判斷中... : 另外您應該有指定GridView1的DataSource是SqlDataSource1吧... : 然後 21~最後可以改寫成(含我之前說的修正) : If GridView1.Rows.Count <=0 Then : SqlDataSource1.InsertCommand = InsertCommandString : SqlDataSource1.Insert() : Response.Write("InsertValue") 'DeBug句子,無此句可省略下二行 : Else '因DeBug關係,需加入此行 : Response.Write("NotInsert") 'DeBug句子,與前二行關聯 : End If : Respnose.Redirect("./Personal.aspx") : 希望可以幫到你!! 這部分,我會再試試看,謝謝你的建議 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.140.2
文章代碼(AID): #1ClyFH9D (Web_Design)
討論串 (同標題文章)
文章代碼(AID): #1ClyFH9D (Web_Design)