Public ss As New ADODB.Connection
Public rs As New ADODB.Recordset
Public Function SsOpen()
On Error Resume Next
ss.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;Persist Security Info=False"
ss.Open
End Function
Public Function SsClose()
On Error Resume Next
ss.Close
End Function
Public Function RsOpen(SQL As String) As ADODB.Recordset
On Error Resume Next
With rs
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open SQL, ss
End With
Set RsOpen = rs
End Function
Public Function RsClose()
On Error Resume Next
rs.Close
End Function
'----------------------------------------
'登陆时的代码
Dim rs As New myRs
Private Sub Command1_Click()
rs.SsOpen
rs.RsOpen "select * from 用户 where 用户名='" + Text1.Text + "' and 密码='" + Text2.Text + "'"
If rs.rs.EOF Then
MsgBox "你输入的用户名或密码错误!", 0, "提示"
Text2.Text = ""
Text1.SetFocus
rs.RsClose
rs.SsClose
Exit Sub
End If
mainfrm.Show
username = rs.rs.Fields("用户名")
usercontrol = rs.rs.Fields("权限")
rs.RsClose
rs.SsClose
Unload Me
End Sub
Private Sub Command2_Click()
End
End Sub
---------------------------
'模块里的定义
Public username As String
Public usercontrol As String