Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Access Objects .

Similar presentations


Presentation on theme: "Data Access Objects ."— Presentation transcript:

1 Data Access Objects 

2 DBEngine Object The DBEngine object contains and controls all other objects in the hierarchy of DAO objects.

3 DBEngine Object-Methods
Name Description BeginTrans Begins a new transaction. Read/write Database. CommitTrans Ends the current transaction and saves the changes. CreateDatabase Creates a new Database object, saves the database to disk, and returns an opened Database object (Microsoft Access workspaces only). . CreateWorkspace Creates a new Workspace object. OpenConnection Opens a Connection object on an ODBC data source (ODBCDirect workspaces only). OpenDatabase Opens a specified database and returns a reference to the Database object that represents it. Rollback Ends the current transaction and restores the databases in the Workspace object to the state they were in when the current transaction began.

4 DBEngine Object-Properties
Name Description DefaultPassword Sets the password used to create the default Workspace when it is initialized. Read/write String. DefaultType Sets or returns a value that indicates what type of workspace will be used by the next Workspace object created. DefaultUser Sets the user name used to create the default Workspace when it is initialized. Read/write String. Errors Returns an Errors collection that contains all of the stored Error objects for the specified object. Read-only. IniPath Sets or returns information about the Windows Registry key that contains values for the Microsoft Access database engine (Microsoft Access workspaces only). LoginTimeout Sets or returns the number of seconds before an error occurs when you attempt to log on to an ODBC database. Properties Returns the Properties collection of the specified object. Read-only. Version Rreturns the version of DAO currently in use. Read-only String. Workspaces Returns a Workspaces collection that contains all of the active, unhidden Workspace objects. Read-only.

5 Database object You use the Database object and its methods and properties to manipulate an open database.

6 Database object-Methods
Name Description Close Closes an open Database. CreateProperty Creates a new user-defined Property object (Microsoft Access workspaces only). . CreateQueryDef Creates a new QueryDef object. CreateTableDef Creates a new TableDef object (Microsoft Access workspaces only). Execute Runs an action query or executes an SQL statement on the specified object. NewPassword Changes the password of an existing Microsoft Access database engine database (Microsoft Access workspaces only). OpenRecordset Creates a new Recordset object and appends it to the Recordsets collection.

7 Database object-Properties
Name Description Connect Sets or returns a value that provides information about the source an open database. Read/write String. Connection Returns the Connection object that corresponds to the database (ODBCDirect workspaces only). Returns the name of the specified object. Read-only String. QueryDefs Returns a QueryDefs collection that contains all of the QueryDef objects of the specified database. Read-only. RecordsAffected Returns the number of records affected by the most recently invoked Execute method. Recordsets Returns a Recordsets collection that contains all of the open recordsets in the for the specified database. Read-only. TableDefs Returns a TableDefs collection that contains all of the TableDef objects stored in the specified database. Read-only. Transactions Returns a value that indicates whether an object supports transactions. Read-only Boolean. Updatable Returns a value that indicates whether you can change a DAO object. Read-only Boolean.

8 Recordset object-Methods
A Recordset object represents the records in a base table or the records that result from running a query. Name Description AddNew Creates a new record for an updatable Recordset object. Clone Creates a duplicate Recordset object that refers to the original Recordset object. Close Closes an open Recordset. Edit Copies the current record from an updatable Recordset object to the copy buffer for subsequent editing. FindFirst Locates the first record in a dynaset- or snapshot-type Recordset object that satisfies the specified criteria and makes that record the current record (Microsoft Access workspaces only). FindLast Locates the last record in a dynaset- or snapshot-type Recordset object that satisfies the specified criteria and makes that record the current record (Microsoft Access workspaces only).

9 Recordset object-Methods
Name Description GetRows Retrieves multiple rows from a Recordset object. Move Moves the position of the current record in a Recordset object. MoveFirst Moves to the first record in a specified Recordset object and make that record the current record. MoveLast Moves to the last record in a specified Recordset object and make that record the current record. MoveNext Moves to the next record in a specified Recordset object and make that record the current record. MovePrevious Moves to the previous record in a specified Recordset object and make that record the current record. Requery Updates the data in a Recordset object by re-executing the query on which the object is based. Seek Locates the record in an indexed table-type Recordset object that satisfies the specified criteria for the current index and makes that record the current record (Microsoft Access workspaces only). Update Saves the contents of the copy buffer to an updatable Recordset object.

10 Recordset object-Properties
Name Description BOF Returns a value that indicates whether the current record position is before the first record in a Recordset object. Read-only Boolean. Bookmark Sets or returns a bookmark that uniquely identifies the current record in a Recordset object. EOF Returns a value that indicates whether the current record position is after the last record in a Recordset object. Read-only Boolean. Fields Returns a Fields collection that represents all stored Field objects for the specified object. Read-only. Filter Sets or returns a value that determines the records included in a subsequently opened Recordset object (Microsoft Access workspaces only). Read/write String. Index Sets or returns a value that indicates the name of the current Index object in a table-type Recordset object (Microsoft Access workspaces only). LastModified Returns a ookmark indicating the most recently added or changed record. LastUpdated Returns the date and time of the most recent change made to a base table. Read-only Variant. NoMatch Indicates whether a particular record was found by using the Seek method or one of the Find methods (Microsoft Access workspaces only). RecordCount Returns the number of records accessed in a Recordset object, or the total number of records in a table-type Recordset object. or TableDef object. Read-only Long. Updatable Returns a value that indicates whether you can change a DAO object. Read-only Boolean.

11 RecordsetTypeEnum Enumeration
Name Value Description dbOpenDynamic 16 Opens a dynaset-type Recordset dbOpenDynaset 2 dbOpenForwardOnly 8 Opens a forward-only type Recordset dbOpenSnapshot 4 Opens a snapshot-type Recordset dbOpenTable 1 Opens a table-type Recordset

12 Function FindRecordCount(strSQL As String) As Long Dim dbsNorthwind As DAO.Database Dim rstRecords As DAO.Recordset On Error GoTo ErrorHandler Set dbsNorthwind = CurrentDb Set rstRecords = dbsNorthwind.OpenRecordset(strSQL) If rstRecords.EOF Then FindRecordCount = 0 Else rstRecords.MoveLast FindRecordCount = rstRecords.RecordCount End If rstRecords.Close dbsNorthwind.Close Set rstRecords = Nothing Set dbsNorthwind = Nothing Exit Function ErrorHandler: MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description End Function

13 Dim dbsNorthwind As DAO.Database
Dim rstEmployees As DAO.Recordset Set dbsNorthwind = CurrentDb Set rstEmployees = dbsNorthwind.OpenRecordset("Employees") rstEmployees.MoveFirst Do Until rstEmployees.EOF If rstEmployees!Title = "Sales Representative" Then rstEmployees.Edit rstEmployees!Title = "Account Executive" rstEmployees.Update End If rstEmployees.MoveNext Loop

14 QueryDef object-Methods
A QueryDef object is a stored definition of a query in a Microsoft Access database engine database. Name Description Close Closes an open QueryDef. CreateProperty Creates a new user-defined Property object (Microsoft Access workspaces only). Execute Executes an SQL statement on the specified object. OpenRecordset Creates a new Recordset object and appends it to the Recordsets collection.

15 QueryDef object-Properties
Name Description Connect Sets or returns a value that provides information about the source of database used in a pass-through query. Read-only String. Fields Returns a Fields collection that represents all stored Field objects for the specified object. Read-only. MaxRecords Sets or returns the maximum number of records to return from a query against an ODBC data source. RecordsAffected Returns the number of records affected by the most recently invoked Execute method.

16 TableDef object-Methods
A TableDef object represents the stored definition of a base table or a linked table (Microsoft Access workspaces only). Name Description CreateField Creates a new Field object (Microsoft Access workspaces only). . CreateIndex Creates a new Index object (Microsoft Access workspaces only). . CreateProperty Creates a new user-defined Property object (Microsoft Access workspaces only). OpenRecordset Creates a new Recordset object and appends it to the Recordsets collection. RefreshLink Updates the connection information for a linked table (Microsoft Access workspaces only).

17 TableDef object-Properties
Name Description Connect Sets or returns a value that provides information about a linked table. Read/write String. Fields Returns a Fields collection that represents all stored Field objects for the specified object. Read-only. Returns or sets the name of the specified object. Read/write String. RecordCount Returns the total number of records in a TableDef object. Read-only Long. SourceTableName Sets or returns a value that specifies the name of a linked table or the name of a base table (Microsoft Access workspaces only).


Download ppt "Data Access Objects ."

Similar presentations


Ads by Google