Private Sub form_load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strsql As Stringcn.Provider = " microsoft.jet.oledb.4.0"
cn.ConnectionString = "F:\exercise\example\VB\ex1\db1.mdb"
strsql = "select * from unitifo"
cn.Open
Set rs = cn.Execute(strsql)
MsgBox "ado 查询结果为:" & rs.Fields("姓名")End Sub为什么cn.provider建立不起来呢??

解决方案 »

  1.   


    'cn.Provider = " microsoft.jet.oledb.4.0" 
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FalseF:\exercise\example\VB\ex1\db1.mdb;Persist Security Info=" 
      

  2.   

    ......很棘手
    Cn.ConnectionString= "Provider=microsoft.jet.oledb.4.0;datasource=F:\exercise\example\VB\ex1\db1.mdb;"
    strsql = "select * from unitifo" 
    cn.Open 
    Set rs = cn.Execute(strsql) 
    if not rs.eof then MsgBox "ado 查询结果为:" & rs.Fields("姓名") 
      

  3.   

    写的不完整,当然失败了,看完整的
    Private Sub form_load() 
    Dim cn As ADODB.Connection 
    Dim rs As ADODB.Recordset 
    Dim strsql As String,ConnectionString  As String
    ConnectionString = "provider=Microsoft.Jet.oledb.4.0;Data Source="
        ConnectionString = ConnectionString & "F:\exercise\example\VB\ex1\db1.mdb"& ";Persist Security Info=True"
        cn.Open ConnectionString
    strsql = "select * from unitifo" 
    rs.open sqlstr,cn, adOpenKeyset, adLockReadOnly
    if rs.eof=false then
      MsgBox "ado 查询结果为:" & rs.Fields("姓名") 
    endif
    End Sub      
      

  4.   


    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\exercise\example\VB\ex1\db1.mdb;Persist Security Info=False
      

  5.   


    'Provider 和 DefaultDatabase 属性范例
    '该范例通过打开三个使用不同提供者的 Connection 对象演示 Provider 属性。
    '还使用DefaultDatabase 属性设置 Microsoft ODBC 提供者的默认数据库。Public Sub ProviderX()   Dim cnn1 As ADODB.Connection
       Dim cnn2 As ADODB.Connection
    Dim cnn3 As ADODB.Connection   ' 使用 Microsoft ODBC 提供者打开连接。
       Set cnn1 = New ADODB.Connection
       cnn1.ConnectionString = "driver={SQL Server};" & _
          "server=bigsmile;uid=sa;pwd=pwd"
       cnn1.Open strCnn
       cnn1.DefaultDatabase = "pubs"
       
       ' 显示提供者。
       MsgBox "Cnn1 provider: " & cnn1.Provider   ' 使用 Microsoft Jet 提供者打开连接。
       Set cnn2 = New ADODB.Connection
       cnn2.Provider = "Microsoft.Jet.OLEDB.3.51"
       cnn2.Open "C:\Samples\northwind.mdb", "admin", ""   ' 显示提供者。
       MsgBox "Cnn2 provider: " & cnn2.Provider   ' 使用 Microsoft SQL 服务器提供者打开连接。
       Set cnn3 = New ADODB.Connection
       cnn3.Provider = "sqloledb"
       cnn3.Open "Data Source=srv;Initial Catalog=pubs;", "sa", ""   ' 显示提供者。
       MsgBox "Cnn3 provider: " & cnn3.Provider   cnn1.Close
       cnn2.Close
       cnn3.CloseEnd Sub
      

  6.   


    '程序这样连接数据库就行了
    Private Sub form_load()
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim strsql As String
        
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\exercise\example\VB\ex1\db1.mdb;Persist Security Info=False"
        strsql = "select * from unitifo"
        cn.Open
        Set rs = cn.Execute(strsql)
        MsgBox "ado 查询结果为:" & rs.Fields("姓名")End Sub
      

  7.   

    我是初学者、、不明new是什么意思呢??对象实例化??具体怎么弄呢、、
      

  8.   

    楼主的代码没有实例化cn,加上一句应该就没问题了:
    set cn=new connection
    cn.Provider = " microsoft.jet.oledb.4.0" 
    cn.ConnectionString = "F:\exercise\example\VB\ex1\db1.mdb" 
    cn.Open 
      

  9.   

    修改方法:
    'cn.Provider = " microsoft.jet.oledb.4.0" 
    'cn.ConnectionString = "F:\exercise\example\VB\ex1\db1.mdb" 
    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\exercise\example\VB\ex1\db1.mdb;Persist Security Info=Falsecn.Open 
    strsql = "select * from unitifo" 
    'Set rs = cn.Execute(strsql) 
    rs.open strsql,cn,3,1
    if rs.recordcount > 0 then
        rs.move ?         '想显示出哪行?不循环肯定不会显示全部名称
        MsgBox "ado 查询结果为:" & rs.Fields("姓名")
    else 
        MsgBox "ado 查询结果为空"
    end if
      

  10.   

    cn.Provider = " microsoft.jet.oledb.4.0" 
    cn.ConnectionString = "F:\exercise\example\VB\ex1\db1.mdb" 
    问题不在上面二句,这也是一种常用的标准写法,手边有VB的一试便知....