会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 技巧 > 其它(Other) > 其它技巧 > 正文

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

时间:2006-10-29 21:33 来源:Access开发者 作者:佚名 阅读:
举例数据库为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



(责任编辑:admin)

顶一下
(0)
0%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: