各位,我是用 dao 3.51 访问 Access 97的,可以打开。
    前两天我的Access 97 文件所在的业务软件更新了,就没法访问了,提示 “运行时错误 ‘429’:Activex 部件不能创建对象”。在 win98 上出现,但在 winxp 上可以,我应用 dao3.6 也是不行的。    请各位给出一段访问 Access 97/2000/2003的通用代码 吧,用 dao 或 ado 都行。
  

解决方案 »

  1.   

    dim conn as new adodb.connection
    with conn
        if .state = adstateopen Then .close
        .connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Mode=ReadWrite;Persist Security Info=False"
        .Open
    end with
      

  2.   


        假设有表 “tab1”和字段“age”。
        能否把 查询 表 “tab1”中字段 “age”=25 的所有记录的语句也写一下!
      

  3.   

    dim conn as new adodb.connection
    dim rs as new adodb.recordset
    with conn
        if .state = adstateopen Then .close
        .connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Mode=ReadWrite;Persist Security Info=False"
        .Open
    end withif rs.state=adstateopen then rs.close
    rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
    if rs.recordcount=0 then
        msgbox "没有符合条件的记录!",48,"提示"
    else
        msgobx "共有记录" & rs.recordcount & "条"
    end if
    rs.close
    conn.close
      

  4.   


    还有谁能答复一下!好象跟 ado 或 dao  的版本也有关系呀,能否给段通用的代码?
      

  5.   

    Private Sub Form_Load()
        Dim strConn As String
        Dim pubConn As New ADODB.Connection
        Dim rsTable As New ADODB.Recordset
        Dim strSQL As String    'Access 2000ªº³s±µ
        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\North.mdb;Persist Security Info=False"    pubConn.Open strConn    rsTable.CursorLocation = adUseClient
        strSQL = "select  * from TableName"
        rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
        Set DataGrid1.DataSource = rsTableEnd Sub
      

  6.   

    我的代码如下:
    Private Sub Form_Load()
        Dim dfpath As String '定义
        Dim strConn As String
        Dim pubConn As New ADODB.Connection
        Dim rsTable As New ADODB.Recordset
        Dim strSQL As String
       
        dfpath = App.Path
        If Right(dfpath, 1) <> "\" Then dfpath = dfpath & "\"
        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dfpath & "DataBase\POS97.mdb;Persist Security Info=False"
        pubConn.Open strConn    rsTable.CursorLocation = adUseClient
        strSQL = "select  * from bmem"
        rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
        '我的窗体上有Adodc 控件,名称为Adodc1,请问如何连接到 该控件上
    End Sub
      

  7.   


       请问:
           就以上代码,如何连接到我的 数据控件 Adodc 控件,名称为Adodc1 。
      

  8.   

    自己会连接 Adodc1 了,另外将所有记录显示在 datagrid1 中,代码接在 8 楼代码的最后:
        
        Adodc1.ConnectionString = strConn
        Adodc1.RecordSource = strSQL
        Adodc1.Refresh
        Set DataGrid1.DataSource = Adodc1
        
       现有问题:
       1.  在 2 楼 Leftie(左手,为人民币服务) 的答复中有:
         if .state = adstateopen Then .close
         if rs.state=adstateopen then rs.close
         不知这两句是什么意思???
       2. 在打开表 的代码中 楼上有 2  为弟兄的答复少不一致:
          rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
          rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
          请问以上2 句代码最后 2  个参数不一样,其意思是什么,有区别吗?
      

  9.   

    Option ExplicitPrivate m_Conn As ADODB.Connection
    Private m_Cmd As ADODB.Command
    Public m_Rs As ADODB.Recordset
    Public Function ConnectToServer(ByVal strDBName As String) As Boolean
    On Error GoTo ERR_HANDLE:    Set m_Conn = New ADODB.Connection
        m_Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName
        
        m_Conn.ConnectionTimeout = 30
        m_Conn.Open
        ConnectToServer = True
        Exit Function
        
    ERR_HANDLE:
        MsgBox "Error NO.:" & Err.Number & vbCrLf & "Error Description:" & Err.Description, vbCritical + vbOKOnly, "Error"
        ConnectToServer = False
        
    End FunctionPublic Function ExecuteSQL(ByVal strSQLQuery As String) As Boolean
    On Error GoTo ERR_HANDLE:
        
        Set m_Cmd = New Command
        
        With m_Cmd
            .ActiveConnection = m_Conn
            .CommandTimeout = 30
            .CommandType = adCmdText
            .CommandText = strSQLQuery
            .Execute
        End With
        ExecuteSQL = True
        Set m_Cmd = Nothing
        Exit Function
        
    ERR_HANDLE:
        MsgBox "Error NO.:" & Err.Number & vbCrLf & "Error Description:" & Err.Description, vbCritical + vbOKOnly, "Error"
        ExecuteSQL = False
        
    End FunctionPrivate Sub Class_Terminate()
        On Error Resume Next
        If Not (m_Rs Is Nothing) Then m_Rs.Close
        Set m_Rs = Nothing
        If Not (m_Conn Is Nothing) Then m_Conn.Close
        Set m_Conn = Nothing
    End SubPublic Function GetRecordset(ByVal strSQL As String) As Boolean
    On Error GoTo ERR_HANDLE:
        
        Set m_Rs = New Recordset
        
        m_Rs.Open strSQL, m_Conn, adOpenDynamic, adLockOptimistic
        
        GetRecordset = True
        Exit Function
        
    ERR_HANDLE:
        MsgBox "Error NO.:" & Err.Number & vbCrLf & "Error Description:" & Err.Description, vbCritical + vbOKOnly, "Error"
        GetRecordset = False
    End Function
      

  10.   

    现有问题:
       1.  在 2 楼 Leftie(左手,为人民币服务) 的答复中有:
         if .state = adstateopen Then .close
         if rs.state=adstateopen then rs.close
         不知这两句是什么意思???
       2. 在打开表 的代码中 楼上有 2  为弟兄的答复少不一致:
          rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
          rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
          请问以上2 句代码最后 2  个参数不一样,其意思是什么,有区别吗?
      

  11.   

    现有问题:
       1.  在 2 楼 Leftie(左手,为人民币服务) 的答复中有:
         if .state = adstateopen Then .close
         if rs.state=adstateopen then rs.close
         不知这两句是什么意思???解释:这两句是判断RecordSet的状态,目的是关闭记录集。   2. 在打开表 的代码中 楼上有 2  为弟兄的答复少不一致:
          rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
          rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
          请问以上2 句代码最后 2  个参数不一样,其意思是什么,有区别吗?解释:第一个参数是游标,第二个参数是锁定方式上面介绍的都是ADO的语法,如果要用DAO来解决的话,只需要将DAO 3.51换成DAO 4.0就可以了,源程序不需要做任何修改!!
      

  12.   

    谢谢 CityBird(鹰扬九洲——只有想不到的,没有做不到的) (为什么 说要换 只需要将DAO 3.51换成DAO 4.0就可以了?