首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

更改数据库客户密码的操作,该怎么解决

2012-01-31 
更改数据库客户密码的操作请大家帮忙看看?的地方该如何填写相应代码?privatevoidbutton1_Click(objectsend

更改数据库客户密码的操作
请大家帮忙看看?的地方该如何填写相应代码?
private   void   button1_Click(object   sender,   EventArgs   e)
                {
                        if   (textBox1.Text   !=   " "   &&   textBox2.Text   !=   " "   &&   textBox3.Text   !=   " ")
                        {
                                if   (textBox1.Text   ==   ?)//个人觉得是数据库该表中的数据,但是不之怎末写??
                                {
                                        if   (textBox2.Text   ==   textBox3.Text)
                                        {
                                                SqlConnection   Conn   =   new   SqlConnection( "Data   Source=(local);Integrated   Security=SSPI;Initial   Catalog=myaa ");
                                                SqlCommand   cmd   =   new   SqlCommand( "update     tb_Admini   set   pwd= ' "   +   textBox2.Text   +   " '   where   id= ' "   ?(这里怎末写sql语句)   " ' ",   Conn);
                                                Conn.Open();
                                            cmd.ExecuteNonQuery();
                                                Conn.Close();
                                            ?(这里对应这么写)   =   textBox2.Text;
                                                MessageBox.Show( "新口令设置成功! ", "信息提示 ");
                                                Close();
                                        }
                                        else
                                        {
                                                MessageBox.Show( "两次密码输入不同! ",   "信息提示 ");


                                                textBox2.Focus();
                                                textBox2.SelectAll();
                                        }
                                }
                                else
                                {
                                        MessageBox.Show( "旧密码不正确! ",   "信息提示 ");
                                        textBox1.Focus();
                                        textBox1.SelectAll();
                                }
                        }
                        else
                        {
                                MessageBox.Show( "请输入完整! ", "信息提示 ");
                        }

[解决办法]
一塌糊涂

To:
if (textBox1.Text == ?)//个人觉得是数据库该表中的数据,但是不之怎末写??
这里是查找用户名吧 应该搜索数据库 看用户是否存在

To:
"update tb_Admini set pwd= ' " + textBox2.Text + " ' where id= ' " ?(这里怎末写sql语句) " ' "
改为 "update tb_Admini set pwd= ' " + textBox2.Text + " ' where id= ' " + 要修改密码的ID号 + " ' "
[解决办法]
还少一个用户id的字段
这里假设userName 为你数据库中的id字段
string userName= " ";
if(userName == " " || textBox1.Text== " " || textBox2.Text== " " || textBox3.Text== " "){
MessageBox.Show( "请输入完整! ", "信息提示 ");
return;
}

if(textBox2.Text != textBox3.Text){
MessageBox.Show( "两次密码输入不同! ", "信息提示 ");
textBox2.Focus();
textBox2.SelectAll();
return;
}
SqlConnection Conn = new SqlConnection( "Data Source=(local);Integrated Security=SSPI;Initial Catalog=myaa ");
SqlCommand cmd = new SqlCommand(String.Format( "select pwd from tb_Admini where id= '{0} ' ",userName),Conn);

Conn.Open();

object o = cmd.ExecuteScalar();
if(o==null){
MessageBox.Show( "用户名不正确! ");
Conn.Close();
return;
}
if(o.ToString()textBox1.Text){
MessageBox.Show( "旧密码不正确! ", "信息提示 ");


textBox1.Focus();
textBox1.SelectAll();
}
cmd.CommandText = String.Format( "update tb_Admini set pwd= '{0} ' where id= '{1} ' ",userName,textBox2.Text);
cmd.ExecuteNonQuery();
Conn.Close();
MessageBox.Show( "新口令设置成功! ", "信息提示 ");

热点排行