Hi,
Plzz help how to pass session value to a method you have called?
Thanks in advance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Jun 17, 2011, 8:02 AM
1. SELECT Password from login_master ==> for all users, why don't for the logged in user?
SELECT Password from login_master where userid = usersession/userid
2. Then compare the result from above query with oldpassword.
3. The error is due to CommandBehavior.CloseConnection, remove this line.
Because after that you trying to ExecuteNonQuery without a opened connection.
Pankaj GogoiPosted Jun 17, 2011, 6:44 AM
The reason it goes to the else part is because it is false. There must be some exception happened in the changepassword method which is returning false. You might want to debug that function. Is your connection properly initialized.
Is your password stored in plain text or encoded format.
Thanks
Nethra R SPosted Jun 16, 2011, 4:44 AM
protected void btnchangepassword_Click(object sender, EventArgs e)
{
try
{
string oldpass = obje.base64Encode(txtoldpassword.Text);
string confirmpass = obje.base64Encode(txtconfirmpassword.Text);
if (obj.changepwd(oldpass, confirmpass, Session["user"].ToString()))
{
Label1.Text = "Password changed successfully";
}
else
{
Label1.Text = "Please enter the correct password";
}
}
catch(Exception ex)
{
Label1.Text= ex.Message;
}
}
Nethra R SPosted Jun 16, 2011, 4:06 AM
I have created a new connection object but still it is not working
Posted Jun 16, 2011, 3:52 AM
Nethra R SPosted Jun 16, 2011, 3:43 AM
public bool changepwd(string oldpassword,string @newpassword,string usersession)
{
bool returnres = false;
string encryptpass = obj.base64Encode(oldpassword);
try
{
//if (CON.State != ConnectionState.Open)
//{
// CON.Open();
string SQLquery;
SQLquery = "SELECT Password from login_master";
SqlCommand CMD = new SqlCommand(SQLquery, CON);
CON.Open();
DTR = CMD.ExecuteReader(CommandBehavior.CloseConnection);
while (DTR.Read())
{
if (DTR["Password"].ToString() == oldpassword)
{
//DTR.Close();
CONN.Open();
SqlCommand CCMD = new SqlCommand("UPDATE login_master SET Password='" + @newpassword + "' WHERE UserName='" + usersession + "' ", CONN);
CCMD.ExecuteNonQuery();
break;
}
}
DTR.Close();
//}
//else
//{
// CON.Close();
//}
}
catch
{ }
finally
{
CON.Close();
CONN.Close();
}
return returnres;
}
Posted Jun 16, 2011, 3:04 AM
Nethra R SPosted Jun 16, 2011, 2:51 AM
I am getting this error plzz correct me:
There is already an open DataReader associated with this Command which must be closed first.
The code is as follows[which is a method i am calling at change password button click]:
public bool changepwd(string oldpassword,string @newpassword,string usersession)
{
bool returnres = false;
string encryptpass = obj.base64Encode(oldpassword);
try
{
//if (CON.State != ConnectionState.Open)
//{
// CON.Open();
string SQLquery;
SQLquery = "SELECT Password from login_master";
SqlCommand CMD = new SqlCommand(SQLquery, CON);
CON.Open();
DTR = CMD.ExecuteReader(CommandBehavior.CloseConnection);
while (DTR.Read())
{
if (DTR["Password"].ToString() == oldpassword)
{
CMD = new SqlCommand("UPDATE login_master SET Password='" + @newpassword + "' WHERE UserName='" + usersession + "' ", CON);
CMD.ExecuteNonQuery();
break;
}
}
DTR.Close();
//}
//else
//{
// CON.Close();
//}
}
catch
{ }
finally
{
CON.Close();
}
return returnres;
}
================================================================
At button click event i am passing the values like this:
protected void btnchangepassword_Click(object sender, EventArgs e)
{
string oldpass = obje.base64Encode(txtoldpassword.Text);
string confirmpass = obje.base64Encode(txtconfirmpassword.Text);
if(obj.changepwd(oldpass,confirmpass,Session["user"].ToString()))
{
Label1.Text = "Password changed successfully";
}
else
{
Label1.Text = "Please enter the correct password";
}
}
Posted Jun 16, 2011, 2:37 AM
PoupulateName(strName);
or
PopulateName(Convert.ToString(Session["Name"]));
private void PopulateName(string Name)
{
text1.Text = Name;
}
HTH
Krishna GaradPosted Jun 16, 2011, 2:21 AM
string _variable=(string)Session["Sname"];
method(_variable);
or like bellow
Method(Session["Sname"].ToString());