由于特殊原因需要用DAO访问Sqlserver数据库,求各位老兄给个例子.
不知道对Dao的版本是否有限制,先谢了。

解决方案 »

  1.   

    使用DAO访问数据库的例子:http://www.lihuasoft.net/source/show.php?id=516
      

  2.   

    sqlserver2000的sp 用vb6中的Dao访问:http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=23932
      

  3.   

    Dim cn As DAO.Database
    Set cn = OpenDatabase("", 0, 0, "ODBC;Driver=SQL Server;server=155.29.12.15;UID=sa;PWD=11;DATABASE=deg") 以下是一段帮助中的示例:
    Connection Object, Connections Collection ExampleThis example demonstrates the Connection object and Connections collection by opening a Microsoft Jet Database object and two ODBCDirect Connection objects and listing the properties available to each object.Sub ConnectionObjectX()    D.....................
    ........... 
     
      

  4.   

    Dim cn As DAO.Database
    Set cn = OpenDatabase("", 0, 0, "ODBC;Driver=SQL Server;server=155.29.12.15;UID=sa;PWD=11;DATABASE=deg") 以下是一段帮助中的示例:
    Connection Object, Connections Collection ExampleThis example demonstrates the Connection object and Connections collection by opening a Microsoft Jet Database object and two ODBCDirect Connection objects and listing the properties available to each object.Sub ConnectionObjectX()    Dim wrkJet as Workspace
        Dim dbsNorthwind As Database
        Dim wrkODBC As Workspace
        Dim conPubs As Connection
        Dim conPubs2 As Connection
        Dim conLoop As Connection
        Dim prpLoop As Property    ' Open Microsoft Jet Database object.
        Set wrkJet = CreateWorkspace("NewJetWorkspace", _
            "admin", "", dbUseJet)
        Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb")    ' Create ODBCDirect Workspace object and open Connection
        ' objects.
        Set wrkODBC = CreateWorkspace("NewODBCWorkspace", _
            "admin", "", dbUseODBC)
        Set conPubs = wrkODBC.OpenConnection("Connection1", , , _
            "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
        Set conPubs2 = wrkODBC.OpenConnection("Connection2", , _
            True, "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")    Debug.Print "Database properties:"    With dbsNorthwind
            ' Enumerate Properties collection of Database object.
            For Each prpLoop In .Properties
                On Error Resume Next
                Debug.Print "  " & prpLoop.Name & " = " & _
                    prpLoop.Value
                On Error GoTo 0
            Next prpLoop
        End With    ' Enumerate the Connections collection.
        For Each conLoop In wrkODBC.Connections
            Debug.Print "Connection properties for " & _
                conLoop.Name & ":"        With conLoop
                ' Print property values by explicitly calling each
                ' Property object; the Connection object does not
                ' support a Properties collection.
                Debug.Print "  Connect = " & .Connect
                ' Property actually returns a Database object.
                Debug.Print "  Database[.Name] = " & _
                    .Database.Name
                Debug.Print "  Name = " & .Name
                Debug.Print "  QueryTimeout = " & .QueryTimeout
                Debug.Print "  RecordsAffected = " & _
                    .RecordsAffected
                Debug.Print "  StillExecuting = " & _
                    .StillExecuting
                Debug.Print "  Transactions = " & .Transactions
                Debug.Print "  Updatable = " & .Updatable
            End With    Next conLoop    dbsNorthwind.Close
        conPubs.Close
        conPubs2.Close
        wrkJet.Close
        wrkODBC.CloseEnd Sub
     
      

  5.   

    OpenConnection Method ExampleThis example uses the OpenConnection method with different parameters to open three different Connection objects.Sub OpenConnectionX()   Dim wrkODBC As Workspace
       Dim conPubs As Connection
       Dim conPubs2 As Connection
       Dim conPubs3 As Connection
       Dim conLoop As Connection   ' Create ODBCDirect Workspace object.
       Set wrkODBC = CreateWorkspace("NewODBCWorkspace", _
          "admin", "", dbUseODBC)   ' Open Connection object using supplied information in 
       ' the connect string. If this information were 
       ' insufficient, you could trap for an error rather than 
       ' go to an ODBC Driver Manager dialog box.
       MsgBox "Opening Connection1..."
       Set conPubs = wrkODBC.OpenConnection("Connection1", _
          dbDriverNoPrompt, , _
          "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")   ' Open read-only Connection object based on information 
       ' you enter in the ODBC Driver Manager dialog box.
       MsgBox "Opening Connection2..."
       Set conPubs2 = wrkODBC.OpenConnection("Connection2", _
          dbDriverPrompt, True, "ODBC;DSN=Publishers;")   ' Open read-only Connection object by entering only the 
       ' missing information in the ODBC Driver Manager dialog 
       ' box.
       MsgBox "Opening Connection3..."
       Set conPubs3 = wrkODBC.OpenConnection("Connection3", _
          dbDriverCompleteRequired, True, _
          "ODBC;DATABASE=pubs;DSN=Publishers;")   ' Enumerate the Connections collection.
       For Each conLoop In wrkODBC.Connections
          Debug.Print "Connection properties for " & _
             conLoop.Name & ":"      With conLoop
             ' Print property values by explicitly calling each
             ' Property object; the Connection object does not
             ' support a Properties collection.
             Debug.Print "  Connect = " & .Connect
             ' Property actually returns a Database object.
             Debug.Print "  Database[.Name] = " & _
                .Database.Name
             Debug.Print "  Name = " & .Name
             Debug.Print "  QueryTimeout = " & .QueryTimeout
             Debug.Print "  RecordsAffected = " & _
                .RecordsAffected
             Debug.Print "  StillExecuting = " & _
                .StillExecuting
             Debug.Print "  Transactions = " & .Transactions
             Debug.Print "  Updatable = " & .Updatable
          End With   Next conLoop   conPubs.Close
       conPubs2.Close
       conPubs3.Close
       wrkODBC.CloseEnd Sub
      

  6.   

    Database Property ExampleThis example uses the Database property to show how code that used to access ODBC data through the Microsoft Jet database engine can be converted to use ODBCDirect Connection objects.The OldDatabaseCode procedure uses a Microsoft Jet-connected data source to access an ODBC database.Sub OldDatabaseCode()   Dim wrkMain As Workspace
       Dim dbsPubs As Database
       Dim prpLoop As Property   ' Create Microsoft Jet Workspace object.
       Set wrkMain = CreateWorkspace("", "admin", "", dbUseJet)   ' Open a Database object based on information in
       ' the connect string.
       Set dbsPubs = wrkMain.OpenDatabase("Publishers", _
          dbDriverNoPrompt, False, _
          "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")   ' Enumerate the Properties collection of the Database 
       ' object.
       With dbsPubs
          Debug.Print "Database properties for " & _
             .Name & ":"      On Error Resume Next
          For Each prpLoop In .Properties
             If prpLoop.Name = "Connection" Then
                ' Property actually returns a Connection object.
                Debug.Print "  Connection[.Name] = " & _
                   .Connection.Name
             Else
                Debug.Print "  " & prpLoop.Name & " = " & _
                   prpLoop
             End If
          Next prpLoop
          On Error GoTo 0   End With   dbsPubs.Close
       wrkMain.CloseEnd SubThe NewDatabaseCode example opens a Connection object in an ODBCDirect workspace. It then assigns the Database property of the Connection object to an object variable with the same name as the data source in the old procedure. None of the subsequent code has to be changed as long as it doesn't use any features specific to Microsoft Jet workspaces.Sub NewDatabaseCode()   Dim wrkMain As Workspace
       Dim conPubs As Connection
       Dim dbsPubs As Database
       Dim prpLoop As Property   ' Create ODBCDirect Workspace object instead of Microsoft 
       ' Jet Workspace object.
       Set wrkMain = CreateWorkspace("", "admin", "", dbUseODBC)   ' Open Connection object based on information in
       ' the connect string.
       Set conPubs = wrkMain.OpenConnection("Publishers", _
          dbDriverNoPrompt, False, _
          "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
       ' Assign the Database property to the same object 
       ' variable as in the old code.
       Set dbsPubs = conPubs.Database   ' Enumerate the Properties collection of the Database 
       ' object. From this point on, the code is the same as the 
       ' old example.
       With dbsPubs
          Debug.Print "Database properties for " & _
             .Name & ":"      On Error Resume Next
          For Each prpLoop In .Properties
             If prpLoop.Name = "Connection" Then
                ' Property actually returns a Connection object.
                Debug.Print "  Connection[.Name] = " & _
                   .Connection.Name
             Else
                Debug.Print "  " & prpLoop.Name & " = " & _
                   prpLoop
             End If
          Next prpLoop
          On Error GoTo 0   End With   dbsPubs.Close
       wrkMain.CloseEnd Sub