我做了一个修改密码的窗体,请求各位给出我更新代码 谢谢了!!!
有4个TEXT 文本框,分别为 用户名 原密码 新密码 确认新密码
数据库名 datamaster 表名 password 字段名 username passd
代码如下:
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\datamaster.mdb"
Dim sql As String
Dim rs As New ADODB.Recordset
If Trim(Text2.Text = "") Then
        MsgBox "旧密码不能为空,请重新输入!", vbOKOnly + vbExclamation, "警告"
        Text2.Text = ""
        Text2.SetFocus
        Exit Sub
    End If
    If Trim(Text3.Text = "") Then
        MsgBox "新密码不能为空,请重新输入!", vbOKOnly + vbExclamation, "警告"
        Text3.Text = ""
        Text3.SetFocus
        Exit Sub
    End If
    If Text3.Text <> Text4.Text Then
        MsgBox "两次输入的新密码不同,请重新输入!", vbOKOnly + vbExclamation, "警告"
        Text3.Text = ""
        Text4.Text = ""
        Text3.SetFocus
        Exit Sub
    Else
        sql = "select * from [password] where [username] ='" & Text1.Text & "'"
        rs.Open sql, conn, adOpenStatic, adLockReadOnly    '打开返回的可用记录集
        If rs.EOF = True Then
          MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
          Text1.Text = ""
          Text2.Text = ""
          Text3.Text = ""
          Text4.Text = ""
          Text1.SetFocus
        Else
          If Trim(rs.Fields(1)) <> Trim(Text2.Text) Then
              MsgBox "原密码不对,请重新输入!", vbOKOnly + vbExclamation, "警告"
              Text2.Text = ""
              Text3.Text = ""
              Text4.Text = ""
              Text2.SetFocus
          Else
              MsgBox "密码修改成功!", vbOKOnly + vbInformation, "提示"
              Text1.Text = ""
              Text2.Text = ""
              Text3.Text = ""
              Text4.Text = ""
              Text1.SetFocus
            End If
        End If
    End If
这里应该还需要加什么代码实现更新数据库

解决方案 »

  1.   

    sql="UPDATE Password SET password='" & Text1 & "'"
    conn.execute sql
      

  2.   

    If Trim(Rs.Fields(1)) <> Trim(Text2.Text) Then
        MsgBox "原密码不对,请重新输入!", vbOKOnly + vbExclamation, "警告"
        Text2.Text = ""
        Text3.Text = ""
        Text4.Text = ""
        Text2.SetFocus
    Else
        conn.Execute ("UPDATE Password SET [password]='" & Text3.Text & "' where [username] ='" & Text1.Text & "'")
        MsgBox "密码修改成功!", vbOKOnly + vbInformation, "提示"
        Text1.Text = ""
        Text2.Text = ""
        Text3.Text = ""
        Text4.Text = ""
        Text1.SetFocus
    End If
      

  3.   

     conn.Execute ("insert into Password ([username],[password]) values('" & Text1.Text & "', '" & Text3.Text & "')")  conn.Execute ("delete from Password  where [username] ='" & Text1.Text & "'") 
      

  4.   

    大哥,那个conn.Execute 不对,运行时候提示错误 “updata 语句的语法错误”