VB 需修改密码模块代码

来源:百度知道 编辑:UC知道 时间:2024/06/15 14:31:31
所做系统为VB和ACCESS,最简单的那种,可以修改密码就行,需要代码.我自己的代码貌似不能用,或者帮我修改下也行.
我自己的代码是
Private Sub Command1_Click()

Dim sql As String
Dim rs_chang As New ADODB.Recordset '声明rs_chang为对象类型的变量
Dim conn As New ADODB.Connection '声明conn 为对象类型的变量
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\facility.mdb" 'App.path指定.VBP工程文件的路径
If Trim(Text1.Text) <> Trim(Text2.Text) Then
MsgBox "密码不一致!", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Else
sql = "select * from 系统管理 where 用户名='" & userID & "'"
rs_chang.Open sql, conn, adOpenKeyset, adLockPessimistic
rs_chang.Fields(1) = Text1.Text
rs_chang.Update
rs_chang.Close
MsgBox "密码修改成功", vbOKOnly + vbExclamation, ""
Unload Me
End If
End Sub

例:窗口一个form1,按钮两个cmdok,cmdcancel,文本框三个txtold,txtnewm,txtcheck,数据库名testdb,用户表user,用户名字段u_name,口令字段u_pass

代码:
private sub cmdcancel_click()
unload me
end sub

private sub cmdok_click()
if txtold.text="" and txtnew.text="" and txtcheck.text="" then
msgbox "确保旧口令或校验口令不为空!"
exit sub
end if
if txtnew.text<>txtcheck.text then
msgbox "两次输入口令不一致!"
exit sub
end if
dim connstr as string
connstr="provider=microsoft.jet.oledb.4.0;data source=" & app.path & "\testdb.mdb"
dim conn as new adodb.connection
conn.open connstr
dim rs as new adodb.recordset
dim sql as string
sql="select * from user where u_name='" & 用户名 & "'"
rs.open sql,conn,3,3
if rs("user_pass")<>txtold.text then
msgbox "原口令错误!"
rs.close
conn.clo