求助!关于登录界面打开和关闭数据库的问题
描述:窗体加载即连接数据库按,以便验证登录信息正确与否;若正确,关闭此窗体进行下次连接;问题:我是在Form_load里面打开的数据库,不知道从拿下手关闭,导致下个窗体连接失败,请各位不吝赐教,万分感谢!
过程如下:
Option Explicit
Dim cnt As Integer
Dim conn As New ADODB.Connection
Dim userID As String
Dim userpow As String
---------------------------------
Private Sub Form_Load()
Dim connectionstring As String
Dim rs_login As New ADODB.Recordset
connectionstring = "provider=Microsoft.Jet.oledb.4.0;" & "data source=D:\vb6\实例\登录设定\xiayier.mdb"
conn.Open connectionstring
cnt = 0
End Sub
--------------------------------
Private Sub Image1_Click()
Dim sql As String
Dim rs_login As New ADODB.Recordset
If Trim(text1.Text) = "" Then
MsgBox "该用户名无效,请重新输入!", vbOKOnly + vbExclamation, "系统提示"
text1.SetFocus
text1.Text = ""
text2.Text = ""
Else
sql = "select * from 密码表 where 用户名称='" & text1.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "该用户名无效,请重新输入!", vbOKOnly + vbExclamation, "系统提示"
text1.SetFocus
text1.Text = ""
text2.Text = ""
Else
If Trim(rs_login.Fields(2)) = Trim(text2.Text) Then
userID = text1.Text
userpow = rs_login.Fields(2)
rs_login.Close
Unload Me
Form2.Show
Else
MsgBox "密码不正确,请重新输入", vbOKOnly + vbExclamation, "系统提示"
text2.SetFocus
text1.Text = ""
text2.Text = ""
End If
End If
End If
cnt = cnt + 1
If cnt = 5 Then
Unload Me
End If
Exit Sub
rs_login.Close
Set rs_login = Nothing
End Sub
请问各位大侠这个该怎么修改?从哪里去关闭连接?新手盼回。