2012-05-16 57 views
0

我可以使用按鈕單擊將表會話值存儲在表中。在我的代碼下面我想在表中UserName ..將會話數據存儲到表中

這裏是我使用的代碼:

string cmdstr = "select count(*) from Reg where UserName='" + TextBoxaun.Text + "'"; 
SqlCommand checkUser = new SqlCommand(cmdstr, con); 

int temp = Convert.ToInt32(checkUser.ExecuteScalar().ToString()); 
if (temp == 1) 
{ 
    string cmdstr2 = "select Password from Reg where UserName='" + TextBoxaun.Text + "'"; 

    SqlCommand pass = new SqlCommand(cmdstr2, con); 
    string password = pass.ExecuteScalar().ToString(); 
    con.Close(); 

    if (password == TextBoxapass.Text) 
     Session["newapply"] = TextBoxaun.Text; 
} 
+2

**警告**您的代碼有sql注入漏洞。 –

+0

你想做什麼?從表內容存儲會話數據?或將會話數據存儲到表? – Shyju

+0

將會話數據存儲到表格Shyju中 – symon

回答

2

首先,你需要ASP.NET SQL Server Registration Tool

創建ASPState的數據庫之後,必須像這樣改變web.config中的會話狀態模式:

<sessionState mode="SQLServer" 
       sqlConnectionString="[Database connection string]"/> 

PS當您使用SQLServer或StateServer模式時,對象必須是可序列化的。欲瞭解更多詳情,請參閱Session-State Modes