How to bind Microsoft Access forms to ADO recordsets

???? ?????? ???? ??????
???? ID: 281998 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
?????: ?????? ???????? ??????, ?????????????? ?? multiuser ???? ???

?? ???? Microsoft Access ??????? (.mdb) ?? ???? Microsoft Access ????????? (.adp) ???? ???? ???

??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

This article describes what is required to create an updateable form that is bound to an ActiveX Data Objects (ADO)Recordset???????? ???

???? ???????

To bind a Microsoft Access form to a recordset, you must set theRecordsetproperty of the form to a valid Data Access Objects (DAO) or ADORecordset???????? ???

TheRecordset??? Microsoft Access 2000 ??? ???????? ???? ??? ??, ?? ??? DAO ?? ADO ???? ?? ??? ??????? ?? ????? ???? ?? ??? ?? ????Recordset???????? ??? ???????, ??????? ??? ????? 2000 ?????? updateability ???? ??? ADO ??????? MSDataShape ?? SQL Server OLEDB ??????? ?? ????? ???? ???? ???????? 2000 ??? ?? ???? ?? ???? ??? ???????? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
227053ACC2000: ??????? ADO Recordsets ?? ?????? ???? ????-???? ?? ???
Microsoft Access 2002 ??? ?? ??? ???, ??? ???? ??? ?? ???? OLEDB ?? ????? ???? ?? ?? ADO recordset ???? ?? ??? ????? updateable ??????? ?? ???????? ???? ??????? ???? ?? ??? ??? ADO recordset ????? ?? ?? updateable ???? ?? ??? ??????? ?? ??? ??? ??????? ?????????? ?? ?????? ???? ????? ?? ??????? ?????????? ???:
  1. ?????????? ADO recordset updateable ???? ?????? ???
  2. Recordset ??? ?? ??????????, ???? ???? ?????? ???????? ????? ?? ?? ?? ???? ????? ??? ???? ?????? ???
???? ?????????? updateability ?? ??? ???? ????????? ?? ??? ???-??? ??? ?? ???? ????? ???? ?? ?? ???? ?????????? ??? ?? ?? Microsoft SQL Server, ???, ODBC, ?? Oracle OLEDB ??????? ?? ????? ?????

Microsoft SQL Server ?? ??? ??????????

?? ???? ??????? ADO recordset ?? Microsoft SQL Server ?? ????? ???? ?? ??? ????? updateability ?????? ???? ?? ??? ?? ????? ?????????? ??? ????:
  • ADO recordset ??????? ?? ??? ??? ???? ???? ??????? Microsoft Access 10.0 OLEDB ??????? ?? ????? ???? ??????
  • ADO recordset ??????? ?????? ?? ????? ???? Microsoft SQL Server OLEDB ??????? ?? ???? ???? ??????? ?? ??? ????
???::Microsoft Access 10.0 OLEDB ??????? ??? ??? OLEDB ???? ??????? ??? Microsoft Access ????? ???? ?? ??? ????? ??? ?? ???? ??? ?? ?? ??? ??? Microsoft Access ?? ????? ???? ???? ????????? ??? ????? ???? ?? ??? ??????? ???? ???? ??? ??, ?? ?? ???? ????????? ??? ??????? ???? ???

?? ?? Microsoft Access ??? ADO recordsets ????? ???, ???? ??? ?? ?????? ?? ?? ???? ?? ??? ??? ADO ??????? ????? ???? ????? recordset ?????? ???? ???? ADO ??? ?? ???? Access ????????? (ADP) ????; ??? ??????? ??? ???? SQL Server ??????? ?? ??? Microsoft Access ?? ????? ?? ??? ?? ADO ??????? ???? ?? ???? ??? ?? ?? ??? ??? ADO ????????? ??? ???? ??? ??? ????? SQL Server ??????? ?? ????????

Microsoft Access ?? ?????? ????? ADO ??????? ???? ????

??? ?? ???? Access ????????? ???? (.adp) ???? Microsoft SQL Server ??????? ?? ?????? ???? ?? ????? ?? ??? ???, ?? Microsoft Access ?? ????? ?? ??? ?? ?? ADO ??????? ???? ???? ?? ??? ???? ADO ??? ?? ??? ???? ??? ?? ??????? ?? ?????? ????? ???? ??CurrentProject.AccessConnection????

????? ?????? ????????? ???? ?? ?? Microsoft Access ?? ??? ??? ADO ??????? ???? SQL Server ???? ?? ?????? ADO recordset ???? ?? ??? ??????? ?? ????? ???? ?? ??? ???? ?????
  1. ????? ????????? NorthwindCS.adp ??????
  2. ?????? ??????? ?? ??????? ????? ??? ??????
  3. ??????RecordSource??????? ?? ??????? ???? ?? ??? ??????? ????
  4. ??? ????OnOpen????? ????? ????????? ???? ?? ??? ??????? ???:
    Private Sub Form_Open(Cancel As Integer)
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
             
       'Use the ADO connection that Access uses
       Set cn = CurrentProject.AccessConnection
    
       'Create an instance of the ADO Recordset class, and
       'set its properties
       Set rs = New ADODB.Recordset
       With rs
          Set .ActiveConnection = cn
          .Source = "SELECT * FROM Customers"
          .LockType = adLockOptimistic
          .CursorType = adOpenKeyset
          .Open 
       End With
       
       'Set the form's Recordset property to the ADO recordset
       Set Me.Recordset = rs
    
       Set rs = Nothing
       Set cn = Nothing
    End Sub
    					
  5. ?????? ?? ?? ??????? ??? ?????
  6. ??????? ????? ??? ?????? ??????? ?? ??????
  7. ?????, ???????, ?? ??????? ??? ??? ?????? ??????
??? ???? ?? SQL ????? ???? ?? ?????? ??? updateable recordset ???? ?? ??? ??????? ????? ???

???? ??????? ADO ??????? ??? ??? ??

??? ????? ?? ?? ???? ?? ???? ????? ?? ???? ADO ?? ??????? ???? ?? ??? SQL ????? ?? ???????? ?????? ?? ???, ???? ???? ????? ???? ?? ?? approach ??? Access ??????? (.mdb) ?? ???? Access ????????? ???? (.adp) ???? ????????? ?? ????? SQL Server ??????? ?? ?????? ???? ??? ?? ?? ??? ???? ??? ????? ??? ????? ??? ?? ?? ?? ?? approach ?? ????? ????, Microsoft ??????? ???? ?? ?? ?????? ???? ?? ?? ?? ???? ADO ??????? ??? ??? ?????? ?? ???, ?? ???? ?? ?? ??????? ?? ????? ?? ???? ??? ADO ??????? ?? ??? ???? ?? ????

????????? ???? ?? ????? ?????? ?? ???? ???? ADO ????? ?? ??? ???? Microsoft SQL Server ??????? ?? ??? ?? ??? ???? ??????? ?? ????? ???? ?? ??? ???????:
  1. ????? ??????? Northwind.mdb ??????
  2. ?????? ??????? ?? ??????? ????? ??? ??????
  3. ??????RecordSource??????? ?? ??????? ???? ?? ??? ??????? ????
  4. ??? ????OnOpen????? ????? ????????? ???? ?? ??? ??????? ???:
    Private Sub Form_Open(Cancel As Integer)
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
             
       'Create a new ADO Connection object
       Set cn = New ADODB.Connection
    
       'Use the Access 10 and SQL Server OLEDB providers to
       'open the Connection
       'You will need to replace MySQLServer with the name
       'of a valid SQL Server
       With cn
          .Provider = "Microsoft.Access.OLEDB.10.0"
          .Properties("Data Provider").Value = "SQLOLEDB"
          .Properties("Data Source").Value = "MySQLServer"
          .Properties("User ID").Value = "sa"
          .Properties("Password").Value = ""
          .Properties("Initial Catalog").Value = "NorthwindCS"
          .Open
       End With
    
       'Create an instance of the ADO Recordset class, and
       'set its properties
       Set rs = New ADODB.Recordset
       With rs
          Set .ActiveConnection = cn
          .Source = "SELECT * FROM Customers"
          .LockType = adLockOptimistic
          .CursorType = adOpenKeyset
          .Open 
       End With
       
       'Set the form's Recordset property to the ADO recordset
       Set Me.Recordset = rs
       Set rs = Nothing
       Set cn = Nothing
    End Sub
    					
  5. ??????? ?? ????? ????? ??? ????? ??? ??????:
    Private Sub Form_Unload(Cancel As Integer)
       'Close the ADO connection we opened
       Dim cn As ADODB.Connection
       Set cn = Me.Recordset.ActiveConnection
       cn.Close
       Set cn = Nothing
    End Sub
    					
  6. ??????? ??????, ?? ???? ??? ??? ?????
  7. ??????? ????? ??? ?????? ??????? ?? ??????
  8. ?????, ???????, ?? ??????? ??? ??? ?????? ??????
??? ???? ?? SQL ????? ???? ?? ?????? ??? updateable recordset ???? ?? ??? ??????? ????? ???

Microsoft Jet ?? ??? ??????????

??? ?? ???? ?? ??? Jet ??????? ?? ???? ?? ????? ?? ??? ?? ?? ADO recordset ???? ?? ??? ??????? ?? ????? ???? ?? ???, Microsoft ??????? ???? ?? ?? ?? ???? ???? DAO ?? ?????? DAO ?? ??? ?? ??? ???????? ?? ?? ?? ?????????? ADO ?? ??? Jet ??????? ?? ??? ????? ?? ?? ???? ???

?? ?? ??? ??????? ?? ??? ????? ??? ADO recordset Microsoft Jet ????, ?? ????? ???? ??? ?? ?????? ???:
  • RecordsetActiveConnectionMicrosoft Access 10.0 OLEDB ???? ???????, ??? ?? Microsoft Jet 4.0 OLEDB ???? ??????? ??? ?? ????? ????, ??recordset ???? ?????-???? ????? ???? ?????? ???

    -??-
  • RecordsetActiveConnection??? ???? Microsoft Jet 4.0 OLEDB ???? ??????? ?? ????? ????, ??recordset ?? ???????-???? ????? ???? ?????? ???
???? ?? ???? ??? "Microsoft SQL Server" ??? ?? ???? ???? ??, ???? ??? ??? ?????? ?? ?? ??? ??? ADO ??????? ?? ????? ?? ????? recordset ?????? ??? Jet ??????? ?? ????? ?? ??? ??? ???? ADO ??? ??? ??????? ????? ?? ??? (.mdb) ??????? ??? ???? Microsoft Access ?? ????? ?? ??? ?? ?? ADO ??????? ???? ?? ???? ??? ?? ?? ????????? ?? ???? ??? ??? ?? ADO ??????? ??? ???? ???, ??????? ??????

Microsoft Access ?? ?????? ????? ADO ??????? ???? ????

??? ?? ?? ?? Microsoft Access ??????? ??? ??? ???? ?? ??? ??? (.mdb) ?????? ???? ?? ?? ???? recordset ?? ???????? ??, ?? Microsoft Access ?? ????? ?? ADO ??????? ???? ???? ?? ??? ???? ADO ??? ?? ??? ??????? ??? ?? ??????? ?? ?????? ????? ???? ??CurrentProject.AccessConnection???? ????? ?????? ????????? ???? ?? ?? Microsoft Access ?? ????? ??????? ??? ?? ?? ADO ??????? ???? ?????? ??? Jet ??????? ??? ??? ADO recordset ???? ?? ??? ??????? ?? ????? ???? ?? ??? ???? ????:
  1. ????? ??????? Northwind.mdb ??????
  2. ?????? ??????? ?? ??????? ????? ??? ??????
  3. ??????RecordSource??????? ?? ??????? ???? ?? ??? ??????? ????
  4. ??? ????OnOpen????? ????? ????????? ???? ?? ??? ??????? ???:
    Private Sub Form_Open(Cancel As Integer)
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
                    
       Set cn = CurrentProject.AccessConnection
    
       'Create an instance of the ADO Recordset class, and
       'set its properties
       Set rs = New ADODB.Recordset
       With rs
          Set .ActiveConnection = cn
          .Source = "SELECT * FROM Customers"
          .LockType = adLockOptimistic
          .CursorType = adOpenKeyset
          .CursorLocation = adUseServer
          .Open 
       End With
       
       'Set the form's Recordset property to the ADO recordset
       Set Me.Recordset = rs
       Set rs = Nothing
       Set cn = Nothing
    End Sub
    					
  5. ??????? ??????, ?? ???? ??? ??? ?????
  6. ??????? ????? ??? ?????? ??????? ?? ??????
  7. ?????, ???????, ?? ??????? ??? ??? ?????? ??????
????? ??? ?? ??????? ??? ???? ?? ????? ?? ???? updateable recordset ???? ?? ??? ????? ???

???? ??????? ADO ??????? ??? ??? ??

??? ????? ?? ?? ???? ?? ???? ????? ?? ???? ADO ?? ??????? ???? ?? ??? ??? Jet ??????? ?? ???????? ?????? ?? ???, ???? ???? ?? ??? ??????? ??? ???? ?? ??????? ?? ??? ???? ?? ?? ??? ?? ?? ???? ??????? ??? ???? ??? ????? ???, ?? ?? approach ?? ????? ????? ????? ??? ?? ?? ?? ?? approach ?? ????? ????, Microsoft ??????? ???? ?? ?? ?????? ???? ?? ?? ?? ???? ADO ??????? ??? ??? ?????? ?? ???, ?? ???? ?? ??? ???? ????? ??? ADO ?? ??? ??? ????? ????? ????????

????? ?????? ????????? ???? ?? ?? ?? ???? ?? ??? ??????? ?? ????? ???? ?? ??? ?? ???? ADO ??????? ?? ???? Microsoft Jet ??????? ?? ????? ?? ??? ???? ????:
  1. ?? ??? ????? ??????? ??????
  2. ????? ?? ?????? ??????? ?? ???? Northwind.mdb ????????
  3. ?????? ??????? ?? ??????? ????? ??? ??????
  4. ??????RecordSource??????? ?? ??????? ???? ?? ??? ??????? ????
  5. ??? ????OnOpen????? ????? ????????? ???? ?? ??? ??????? ???:
    Private Sub Form_Open(Cancel As Integer)
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
             
       'Create a new ADO Connection object
       Set cn = New ADODB.Connection
    
       With cn
          .Provider = "Microsoft.Access.OLEDB.10.0"
          .Properties("Data Provider").Value = "Microsoft.Jet.OLEDB.4.0"
          .Properties("Data Source").Value = _
              "C:\Program Files\Microsoft Office\Office10" & _
              "\Samples\Northwind.mdb"
          .Open
       End With
    
       'Create an instance of the ADO Recordset class, and
       'set its properties
       Set rs = New ADODB.Recordset
       With rs
          Set .ActiveConnection = cn
          .Source = "SELECT * FROM Customers"
          .LockType = adLockOptimistic
          .CursorType = adOpenKeyset
          .Open 
       End With
       
       'Set the form's Recordset property to the ADO recordset
       Set Me.Recordset = rs
       Set rs = Nothing
       Set cn = Nothing
    End Sub
    					
  6. ??????? ?? ????? ????? ??? ????? ??? ??????:
    Private Sub Form_Unload(Cancel As Integer)
       'Close the ADO connection we opened
       Dim cn As ADODB.Connection
       Set cn = Me.Recordset.ActiveConnection
       cn.Close
       Set cn = Nothing
    End Sub
    					
  7. ??????? ??????, ?? ???? ??? ??? ?????
  8. ??????? ????? ??? ?????? ??????? ?? ??????
  9. ?????, ???????, ?? ??????? ??? ??? ?????? ??????
????? ??? ?? ??????? ??? ???? ?? ????? ?? ???? updateable recordset ???? ?? ??? ????? ???

ODBC ?? ??? ??????????

?? ?? ??? ODBC ??????? ?? ???? ?? ????? ?? ??? ?? ?? ADO recordset ???? ?? ??? ??????? ?????, ?? ????? ?????????? ???:
  • ADO ??????? recordset ?????? ????? ???? ???? ?? ?? Microsoft OLEDB ??????? ODBC ?? ??? ????? ???? ??????
  • ADO recordset ?? ???????-???? ????? ???? ?????? ???
????????? ???? ?? ????? ?????? ?? ???? ?? ADO ????? ?? ??? ??????? ???? ?? ??? ??? ODBC ??????? ?? ????? ???? ??????? ?? ????? ???? ?? ????

???::?? ????? ???? ?? ODBC ??????? ??? ??? ?????? ???????? ?? ??? ?? ????? ?????? ??? Northwind.mdb ????? ??????? ??? ?????? ?????? ?? ??? ??? ?? ?? ????? MyDSN ???-??? ??????? ?? ?????? ???? ?? ??? ???? ODBC ??????? ?? ????? ???? ?? ?? ??? ?? ??? ODBC DSN ???? ???
  1. ????? ??????? Northwind.mdb ??????
  2. ?????? ??????? ?? ??????? ????? ??? ??????
  3. ??????RecordSource??????? ?? ??????? ???? ?? ??? ??????? ????
  4. ??? ????OnOpen????? ????? ????????? ???? ?? ??? ??????? ???:
    Private Sub Form_Open(Cancel As Integer)
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
       Dim strConnection As String
    
       strConnection = "ODBC;DSN=MyDSN;UID=sa;PWD=;DATABASE=Northwind"
       'Create a new ADO Connection object
       Set cn = New ADODB.Connection
    
       With cn
          .Provider = "MSDASQL"
          .Properties("Data Source").Value = strConnection
          .Open
       End With
    
       'Create an instance of the ADO Recordset class, and
       'set its properties
       Set rs = New ADODB.Recordset
       With rs
          Set .ActiveConnection = cn
          .Source = "SELECT * FROM Customers"
          .LockType = adLockOptimistic
          .CursorType = adOpenKeyset
          .CursorLocation = adUseClient
          .Open 
       End With
       
       'Set the form's Recordset property to the ADO recordset
       Set Me.Recordset = rs
       Set rs = Nothing
       Set cn = Nothing
    End Sub
    					
  5. ??????? ?? ????? ????? ??? ????? ??? ??????:
    Private Sub Form_Unload(Cancel As Integer)
       'Close the ADO connection we opened
       Dim cn As ADODB.Connection
       Set cn = Me.Recordset.ActiveConnection
       cn.Close
       Set cn = Nothing
    End Sub
    					
  6. ??????? ??????, ?? ???? ??? ??? ?????
  7. ??????? ????? ??? ?????? ??????? ?? ??????
  8. ?????, ???????, ?? ??????? ??? ??? ?????? ??????
????? ??? ?? ??????? ODBC ???? ?? ?????? ??? updateable recordset ???? ?? ??? ????? ???

Oracle ?? ??? ??????????

?? ?? ???? Oracle ??????? ?? ???? ?? ????? ?? ??? ?? ?? ADO recordset ???? ?? ??? ??????? ?????, ?? ????? ?????????? ???:
  • ADO ??????? recordset ?????? ????? ???? ???? ?? ?? Microsoft OLEDB ??????? Oracle ?? ??? ????? ???? ??????
  • ADO Recordset ?? ???????-???? ????? ???? ?????? ???
????????? ???? ?? ????? ?????? ?? ???? ?? ADO ????? ?? ??? ??????? Oracle ??????? ?? ???? ?? ????? ???? ??????? ?? ????? ???? ?? ????

???::?? ????? ???? ?? Oracle ??????? ??? ??? ?????? ???????? ?? ??? ?? ????? ?????? ??? Northwind.mdb ????? ??????? ??? ?????? ?????? ?? ??? ???
  1. ????? ??????? Northwind.mdb ??????
  2. ?????? ??????? ?? ??????? ????? ??? ??????
  3. ??????RecordSource??????? ?? ??????? ???? ?? ??? ??????? ????
  4. ??? ????OnOpen????? ????? ????????? ???? ?? ??? ??????? ???:
    Private Sub Form_Open(Cancel As Integer)
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
             
       'Create a new ADO Connection object
       Set cn = New ADODB.Connection
    
       With cn
          .Provider = "MSDAORA"
          .Properties("Data Source").Value = "MyOracleServer"
          .Properties("User ID").Value = "username"
          .Properties("Password").Value = "password"          
          .Open
       End With
    
       'Create an instance of the ADO Recordset class, and
       'set its properties
       Set rs = New ADODB.Recordset
       With rs
          Set .ActiveConnection = cn
          .Source = "SELECT * FROM Customers"
          .LockType = adLockOptimistic
          .CursorType = adOpenKeyset
          .CursorLocation = adUseClient
    
          .Open 
       End With
      
       'Set the form's Recordset property to the ADO recordset
       Set Me.Recordset = rs
       Set rs = Nothing
       Set cn = Nothing
    End Sub
    					
  5. ??????? ?? ????? ????? ??? ????? ??? ??????:
    Private Sub Form_Unload(Cancel As Integer)
       'Close the ADO connection we opened
       Dim cn As ADODB.Connection
       Set cn = Me.Recordset.ActiveConnection
       cn.Close
       Set cn = Nothing
    End Sub
    					
  6. ??????? ??????, ?? ???? ??? ??? ?????
  7. ??????? ????? ??? ?????? ??????? ?? ??????
  8. ?????, ???????, ?? ??????? ??? ??? ?????? ??????
????? ??? ?? ??????? Oracle ???? ?? ?????? ??? updateable recordset ???? ?? ??? ????? ???

??????

???????? ??????? ?? ???, Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ????? ????::
281784?? ??? difference ??????? ?? AccessConnection ???
?????-???? ?????? ????? ???? ??? ?? ???? ??? ????? ?? ?? ?? ?? ???????? ?? ?????? ???? ???? ??? ?? Microsoft ?? ???????? ???? ???.. Microsoft ?? ???????? ?? ????? ???????? ?? ??????????? ?? ???? ??? ??? ?? ??????, ?????????? ?? ???? ???? ?????? ?? ??? ???? ??..

???

???? ID: 281998 - ????? ???????: 17 ??????? 2011 - ??????: 3.0
???? ???? ???? ??:
  • Microsoft Office Access 2003
  • Microsoft Access 2002 Standard Edition
??????: 
kbado kbdatabinding kbdatabase kbdesign kbprogramming kbhowto kbmt KB281998 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:281998

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com