VB登陆代码的问题
错误:连接无法用于执行此操作,在此上下文中它可能已被关闭或效提示在:str.Open strSQl, conn, 3, 2
哪位大哥能帮帮小弟,谢谢了
Public conn As ADODB.Connection
Sub main()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=lianxi;Data Source=."
conn.Open
from1.Show '登录界面
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
Text2.SetFocus
Exit Sub
End If
Dim strSQl As String
strSQl = "select * from user where username='" & Trim$(Text1.Text) & "' and password='" & Trim$(Text2.Text) & "' "
Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset
str.CursorLocation = adUseClient
str.Open strSQl, conn, 3, 2
If str.EOF = True Then
MsgBox "对不起,用户名不存在或密码错误 !", vbOKOnly + vbQuestion, "警告"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Else
MsgBox "欢迎使用本系统!", vbOKOnly + vbInformation, "友情提示"
Unload Me
Form2.Show '登录进入的另一个界面
End If
End Sub
补充:VB , 数据库(包含打印,安装,报表)