设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用vb与sql server如何实现登录密码的修改?

1970-1-1 08:00| 发布者: 佚名| 查看: 3082| 评论: 0

举例数据库为SqlUsers,用户表为:Users,用户名字段:UserName,用户密码字段:UserPassword

Public Rs As New ADODB.Recordset
Public Conn As New ADODB.Connection
Public Sub ConnOpen() '打开数据库
On Error GoTo ConnOpenError
Conn.ConnectionString = "driver={sql server};server=(local);uid=sa;pwd=123456;database=SqlUser"
Conn.Open
Exit Sub
ConnOpenError: MsgBox Err.Description
End Sub
Public Sub ConnClose() '关闭数据库
On Error GoTo ConnCloseError
If Conn.State = 1 Then
Conn.Close
Set Conn = Nothing
End If
Exit Sub
ConnCloseError: MsgBox Err.Description
End Sub

Private Sub Command1_Click()
If CmbName.Text = "" Then
MsgBox "对不起,请选择用户名!", vbInformation
Exit Sub
ElseIf txtPwd.Text = "" Then
MsgBox "对不起,请输入旧密码", vbInformation
Exit Sub
ElseIf txtXinPwd.Text = "" Then
MsgBox "对不起,请输入新密码", vbInformation
Exit Sub
End If
Rs.Open "Select * From Users Where UserName = '" & CmbName.Text & "'", Conn, 1, 3
If Rs.EOF And Rs.BOF Then
MsgBox "对不起,用户名不存在!", vbInformation
ElseIf txtPwd.Text <> Rs("UserPassword") Then
MsgBox "对不起,旧密码错误!", vbInformation
Else
Rs("UserPassword") = txtXinPwd.Text
Rs.Update
End If
Rs.Close
End Sub

Private Sub Form_Load()
ConnOpen

End Sub

Private Sub Form_Unload(Cancel As Integer)
ConnClose
End Sub



最新评论

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-26 10:21 , Processed in 0.066008 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部