設為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

用vb與sql server如何實現登錄密碼的修改?

1970-1-1 08:00| 發(fā)布者: 佚名| 查看: 3243| 評論: 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, 2025-7-13 08:00 , Processed in 0.065387 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回頂部