更改密码未在数据库中更新 [英] change password not updated in database

查看:89
本文介绍了更改密码未在数据库中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用以下代码进行更新.
当我尝试更改密码时,我收到警报消息,但在我的数据库中已更新...
我该怎么办?

Hi,
I am using the following code for update.
when I try to change the password, I get alert message but updated in my database...
What do I have to do?

protected void Button1_Click(object sender, EventArgs e)
{
  con.Open();
  string qry = "select uname,pass from usertab";
  SqlCommand cmd = new SqlCommand(qry, con);
  SqlDataReader dr = cmd.ExecuteReader();
  while (dr.Read())
  {
    if (lbuser.Text.Equals(dr[0].ToString()) && (TextBox1.Text.Equals(dr[1].ToString())))
    {
      SqlCommand cmd1 = new SqlCommand("update usertab set pass='" + TextBox2.Text  +"' where uname='"+ lbuser.Text + "' ",con );
                
      //cmd1.ExecuteNonQuery();
      Response.Write("<script>alert('Password Changed')</script>");                
    }
    else
    {
      Label5.Visible = true;
    }
  }
}

推荐答案

您确实意识到您已经注释掉了实际上更新数据库的位,不是吗?
You do realize you commented out the bit which actually updates the database, don''t you?


编写查询,但执行该查询
cmd.ExecuteNonQuery()
write the query but execute that query
cmd.ExecuteNonQuery()


我解决了这个问题..
代码在这里...

受保护的void Button1_Click(对象发送者,EventArgs e)
{
con.Open();
字符串qry =选择uname,从usertab传递";
SqlCommand cmd =新的SqlCommand(qry,con);
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
if(lbuser.Text.Equals(dr [0] .ToString())&&(TextBox1.Text.Equals(dr [1] .ToString()))
{
SqlConnection con1 =新的SqlConnection(数据源= RAGHU-PC \\ SQLExpress;初始目录=缓存;用户ID = sa;密码= sa");
con1.Open();
SqlCommand cmd1 =新的SqlCommand("update usertab set pass ="" + TextBox2.Text +''其中uname ="" + lbuser.Text +",con1);
//dr.Close();
cmd1.ExecuteNonQuery();
//dr.Close();
Response.Write(< script> alert(''Password Changed'')</script>");
}
其他
{
Label5.Visible = true;
}

}


}
i solved this prob..
code is here...

protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
string qry = "select uname,pass from usertab";
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (lbuser.Text.Equals(dr[0].ToString()) && (TextBox1.Text.Equals(dr[1].ToString())))
{
SqlConnection con1 = new SqlConnection("Data Source=RAGHU-PC\\SQLExpress;Initial Catalog=cache;User ID=sa;password=sa");
con1.Open();
SqlCommand cmd1 = new SqlCommand("update usertab set pass=''" + TextBox2.Text + "'' where uname=''" + lbuser.Text + "'' ", con1);
//dr.Close();
cmd1.ExecuteNonQuery();
// dr.Close();
Response.Write("<script>alert(''Password Changed'')</script>");
}
else
{
Label5.Visible = true;
}

}


}


这篇关于更改密码未在数据库中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆