XY_玄远
XY_玄远
关注数: 3
粉丝数: 10
发帖数: 678
关注贴吧数: 5
VB+SQL登录,总显示连接无法执行此操作,它可能在上下文中被关闭 VB+SQL登录,总显示连接无法执行此操作,它可能在上下文中被关闭 不知道问题出在哪里?求高手指点。。。。。 代码如下: Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim Constr As String Private Sub Form_Load() Set conn = New ADODB.Connection Set rs = New ADODB.Recordset Constr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IMDB;Data Source=." conn.Open Constr End Sub Private Sub ULdlCmd_Click() Dim sql As String If Trim(ULIDTxt.Text) = "" Then MsgBox "对不起,请输入用户名", vbInformation, App.Title ULIDTxt.SetFocus Exit Sub ElseIf Trim(ULmmTxt.Text) = "" Then MsgBox "对不起,请输入密码", vbInformation, App.Title ULmmTxt.SetFocus End If sql = "select 用户名,密码 from 用户表 where 用户名='" & ULIDTxt.Text & "'" rs.Open If rs.EOF = True Then MsgBox "用户名不存在!请重新输入", vbInformation, App.Title ULIDTxt.Text = "" ULIDTxt.SetFocus Exit Sub End If If ULmmTxt.Text = rs.Fields(1) Then IBM.Show Exit Sub Else MsgBox "用户密码错误!请重新输入", vbInformation, App.Title ULmmTxt.Text = "" ULmmTxt.SetFocus End If Unload Userlogin End Sub Private Sub ULtcCmd_Click() If MsgBox("确定要退出吗?", vbQuestion + vbYesNo + vbDefaultButton2, App.Title) = vbYes Then Unload Me End If End Sub
新手求解!未发现数据源名称并且未指定默认驱动程序vb Private Sub Command1_Click() Dim sql As String Dim rs_login As New ADODB.Recordset If Trim(Text1.Text) = "" Then MsgBox "请输入用户名", vbOKOnly + vbInformation,"" Text1.SetFocusElse sql = "select * from 用户信息表 where 用户名='" & Text1.Text & "'" rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic If rs_login.EOF Then MsgBox "没有此用户", vbOKOnly + vbInformation, "" Text1.SetFocus Else If Trim(rs_login.Fields(1)) = Trim(Text2.Text) Then userID = Text1.Text userpow = rs_login.Fields(2) rs_login.Close Unload Me MDIForm1.Show Else MsgBox "密码输入错误,请重新输入", vbOKOnly + vbInformation, "" Text2.SetFocus End If End If End Sub Private Sub Command2_Click() Unload Me End Sub Private Sub Form_Load() Dim connectionstring As String connectionstring = "Provider=Microsoft.Jet.oledb.4.0;" & _ "data source =zpgllink" conn.Open connctionstring End Sub
1
下一页