Reputation: 13
Can i store session value in a table with button click. In my code below I want the UserName
in table..
Here is the code I'm using:
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;
}
Upvotes: 0
Views: 668
Reputation: 5899
First of all, you need ASP.NET SQL Server Registration Tool
After you create ASPState database, you must change session state mode in web.config like this:
<sessionState mode="SQLServer"
sqlConnectionString="[Database connection string]"/>
P.S. When you are using SQLServer or StateServer modes, objects must be serializable. For more details see Session-State Modes
Upvotes: 2