问题可能的IF条件没设置好 ,早上查找资料

string connstr;
SqlConnection myconn=new SqlConnection(connstr);
string sql="select * from userinfo where [user]='"+TextBox1.Text+"'";
SqlDataAdapter myadapter=new SqlDataAdapter(sql,myconn);
DataSet myds=new DataSet();
try
{
myconn.Open();
myadapter.Fill(myds,"userinfo");
if(myds.Tables["userinfo"].Rows.Count!=0)
{
if(myds.Tables["userinfo"].Rows[0]["pwd"]==TextBox2.Text)
{
string update="update userinfo set pwd='"+TextBox3.Text+"' where user='"+TextBox1.Text+"'";
SqlCommand mycmd=new SqlCommand(update,myconn);
mycmd.ExecuteNonQuery();
MessageBox.Show("密码修改成功!");
}
else
{
MessageBox.Show("旧密码不正确!");
}
}
else
{
MessageBox.Show("用户名不正确!");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if(myconn.State==ConnectionState.Open)
{
myconn.Close();
}
}

在整合自己的代码 调用 main类中的cpwd()方法和eidtpwd()方法

 

 main edpwd = new main();
        OleDbDataReader dr = edpwd.cpwd(TextBox2.Text);

        if (dr.Read())
        {
            if (edpwd.eidtpwd(TextBox3.Text) > 0)
            {ee.Text = "密码修改成功!";
            }
            else
            {
                ee.Text = "旧密码不正确!";
            }
        }
        else
        {
            ee.Text = "原始密码或帐号出错!"; return;
        }

    }

 

测试成功~

相关文章:

  • 2021-06-19
  • 2021-11-08
  • 2021-07-01
  • 2022-12-23
  • 2021-09-11
  • 2021-07-29
  • 2021-11-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案