0

ボタンクリックでセッション値をテーブルに保存できますか?以下の私のコードでは、UserNameinテーブルが必要です。

これが私が使用しているコードです:

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;
}
4

1 に答える 1

2

まず、ASP.NETSQLServer登録ツールが必要です

ASPStateデータベースを作成した後、次のようにweb.configでセッション状態モードを変更する必要があります。

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

PS SQLServerまたはStateServerモードを使用している場合、オブジェクトはシリアル化可能である必要があります。詳細については、セッション状態モードを参照してください。

于 2012-05-16T19:08:03.110 に答える