近期写了一个密码登陆窗口用ado 类连接串的使用不熟,测试时显示dbmssocn一般网络错误,不知何故 ,密码表名是mimabiao ;另外用vb调用access2000数据库文件显示不支持此格式mdb文件;Private Sub Command1_Click()
Dim strsql As String
Dim i As String
Dim m As String
'i = Text1.Text
'm = Combo1.Text
'Set gconn = New ADODB.Connection
'
'Dim strconn As String
'strconn = "provider=sqloledb.1;integrated Security=sspi;Persist Security Info=False;intial catalog=mimabiao;datasource=mimabiao;"
'gconn.Open strconn
'
'
' strsql = "select*from mimabiao where xm = '" & Trim(m) & "' and mm='" & Trim(i) & "'"
'Debug.Print strsql
' Dim r As New ADODB.Recordset
' r.Open strsql, gconn, adOpenStatic
' '错误次数
' Static ntrycount As Integer
' If r.EOF Then '登陆失败
'    MsgBox "无此用户或密码", vbCritical, "错误"
'    Text1.SetFocus
'    Text1.SelStart = 0
'    Text1.SelLength = Len(Text1)
'    ntrycount = ntrycount = 1
'
'      If ntrycount >= 3 Then
'          MsgBox "再见!", vbCritical, "无权登陆"
'          Unload Me
'          gconn.Close
'      End If
'Else
'   Unload Me
'   Form3.Show
'   r.Close
''   exitsub
'End If

解决方案 »

  1.   

    'strconn = "provider=sqloledb.1;integrated Security=sspi;Persist Security Info=False;intial catalog=mimabiao;datasource=mimabiao;"mdb的连接字符串不是sql,而是jet4.0
    Option ExplicitPrivate Rs As New ADODB.Recordset
    Private Conn As New ADODB.ConnectionPrivate Sub Form_Load()
     Dim strConn As String
     
     ' 连接数据库的字符串
     ' 连接带密码的数据库,直接在连接符后面加上Jet OLEDB:DataBase Password='您的密码'
     ' 连接Access97数据库需要使用Jet.OLEDB.3.5,Access2K和以上数据库使用Jet.OLEDB.4.0
     strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Persist Security Info=False"
     
     ' 使用客户端数据游标
     Conn.CursorLocation = adUseClient
     ' 打开Access的连接
     Conn.Open strConn
     
     ' 如果RecordSet的状态不是关闭状态,则关闭Recordset
     If Rs.State <> adStateClosed Then Rs.Close
     
     ' Recordser打开表People
     Rs.Open "Select * from People", Conn, adOpenKeyset, adLockOptimistic
     
     ' 报告出 一共多少笔数据,测试是否存在数据
     ' MsgBox Rs.RecordCount
     
     ' 绑定进DataGrid
     Set DataGrid1.DataSource = Rs
     
    End Sub
      

  2.   

    在执行以下操作后;为什么不能进行select语句的查询和输出;能提供一些关联表查询的语句吗
    谢谢!!!!!!!!' Recordser打开表People 
    Rs.Open "Select * from People", Conn, adOpenKeyset, adLockOptimistic
     
     ' 报告出 一共多少笔数据,测试是否存在数据
     ' MsgBox Rs.RecordCount
     
     ' 绑定进DataGrid
     Set DataGrid1.DataSource = Rs
     
    End Sub