用vb做了一个登陆程序,改密码的时候应该怎样改?如图
在用户名密码与原数据相同的情况下才能改,改的时候应该输入怎样的语句?

解决方案 »

  1.   

    这个应该不难,不过你的图没有,也不知道你的登录数据存储在哪里,因此对应你的问题不好回答,做一个用Access数据库存储的例子,供你参考:(数据库名称 ”AA.mdb“,数据表名称” 登录表“。在【工程】-【引用】中添加二个引用:下面是全部代码:
    Dim db As New ADODB.Connection, RS As New ADODB.Recordset, PPID As Long, YMM As StringPrivate Sub Combo1_Click()
    Text1.Text = "": Text2.Text = "": Text3.Text = "": Text4.Text = ""
    PPID = 0: YMM = ""
    Call KKK(db)
    RS.Open "select * from 登录表 Where 用户名='" & Combo1.Text & "'", db, 2, 2
        Text1.Text = RS!用户名
        PPID = RS!ID
        YMM = RS!密码
    RS.Close
    db.Close
    End SubPrivate Sub Command1_Click()
    If PPID = 0 Then
        MsgBox "你没有选择修改密码的用户!"
        Exit Sub
    End If
    If Text2.Text = "" Then
        MsgBox "你没有输入用户原来的密码!"
        Exit Sub
    End If
    If YMM <> Text2.Text Then
          MsgBox "你输入的原密码不正确!"
          Exit Sub
    End If
    If Text3.Text = "" Then
        MsgBox "你没有输入用户新的密码!"
        Exit Sub
    End If
    If Text4.Text = "" Then
        MsgBox "你没有再次输入用户新的密码!"
        Exit Sub
    End If
    If Text3.Text <> Text4.Text Then
        MsgBox "二次输入的新密码不对,请检查!"
        Exit Sub
    End If
    '下面开始修改密码了
    Call KKK(db)
    RS.Open "select * from 登录表 Where ID=" & PPID & " And 用户名='" & Text1.Text & "' And 密码='" & Text2.Text & "'  ", db, 2, 2
          RS!密码 = Text3.Text
          RS.Update
    RS.Close
    db.Close
        MsgBox "这个用户的密码已经修改成功!"
        Unload Me
        Form1.Show
    End SubPrivate Sub Form_Load()
    Combo1.Clear
    Call KKK(db)
    RS.Open "select * from 登录表", db, 2, 2
        Do While Not RS.EOF
        Combo1.AddItem RS!用户名
        RS.MoveNext
        Loop
    RS.Close
    db.Close
    Text1.Text = "": Text2.Text = "": Text3.Text = "": Text4.Text = ""
    PPID = 0: YMM = ""
    End SubPrivate Sub KKK(db)
    db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\AA.mdb;Persist Security Info=False"   '
    End Sub
    下面是程序界面: