Sunteți pe pagina 1din 26

Database Object

A Database object contains other objects (like Table, View, and StoredProcedure objects) which contain or interact with data.

Workspace Object
A workspace is an object that can provide a context for your work separate from other work occurring in the project .

Recordset Object
Represents the entire set of records from a base table or the results of an executed command. When we open a Recordset, the current record is positioned to the first record (if any) and the BOF and EOF properties are set to False. If there are no records, the BOF and EOF property settings are True.

Recordsets type
Table type recordset:The table type recordset object is a set of records that represents a single table which can be used to add,change or delete records.these are the fastest type of recordsets. Dynaset type recordset:The dynaset type recordset object is a set of records that represents a table or queries containing fields from more than one table. A dynaset enables us to update data from more than one table.

Recordsets type contd.


Snapshot type recordset: A snapshot type recordset can refer to any table ,attached table or query. A snapshot can not be updated and does not reflect any change made by the user. Dynamic type recordset:This type of recordset represents a query result set from one or more base tables .Records that the other users add,delete or edit in the base tables also appear in the recordset.this type is only available in ODBS direct workspace. Forward only type recordset:This type of recordset is identical to the snapshot recordset except that we can only scroll forward through its records.

OpenDatabase Method
Opens a specified database in a Workspace object and returns a reference to the Database object that represents it. Syntax Set database = workspace.OpenDatabase (dbname, options, read-only)

Set db = OpenDatabase("C:\Documents and Settings\Indrani Sen\My Documents\product.mdb")

Openrecordset method
The OpenRecordset Method is used to open a recordset and create a recordset variable. Syntax Set recordset =object.OpenRecordset (source, type, options)
Description A String specifying the source of the records for the new Recordset. The source can be a table name, a query name, or an SQL statement that returns records. For table-type Recordset objects in Microsoft Jet databases, the source can only be a table name.

Part source

type options lockedits

Optional. A constant that indicates the type of Recordset to open, as specified in Settings. Optional. A combination of constants that specify characteristics of the new Recordset, as listed in Settings. Optional. A constant that determines the locking for the Recordset, as specified in Settings.

Type argument
You can use one of the following constants for the type argument. dbOpenTable:Opens a table-type Recordset object (Microsoft Jet workspaces only). dbOpenDynamic:Opens a dynamic-type Recordset object, which is similar to an ODBC dynamic cursor. (ODBCDirect workspaces only) dbOpenDynaset:Opens a dynaset-type Recordset object, which is similar to an ODBC keyset cursor. dbOpenSnapshot:Opens a snapshot-type Recordset object, which is similar to an ODBC static cursor. dbOpenForwardOnly :Opens a forward-only-type Recordset object.

options argument.
dbAppendOnly:Allows users to append new records to the Recordset, but prevents them from editing or deleting existing records (Microsoft Jet dynasettype Recordset only). dbSeeChanges:Generates a run-time error if one user is changing data that another user is editing (Microsoft Jet dynaset-type Recordset only). This is useful in applications where multiple users have simultaneous read/write access to the same data. dbDenyWrite:Prevents other users from modifying or adding records (Microsoft Jet Recordset objects only). dbDenyRead:Prevents other users from reading data in a table (Microsoft Jet

table-type Recordset only).


dbInconsistent:Allows inconsistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).dbConsistentAllows only consistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).

Example
Dim wrkMain As Workspace Dim dbsPubs As Database dim rs as recordset Set db=OpenDatabase(d:\Northwind.mdb) Set rs = db.OpenRecordset("product", dbOpenDynaset)

Movefirst method
MoveFirst method to move the current record position to the first record in the Recordset. Dim rs as recordset rs.movefirst

Movelast method
MoveLast method moves the current record position to the last record in the Recordset. Dim rs as recordset rs.movelast

MoveNext
MoveNext method moves the current record position one record forward . (toward the bottom of the Recordset). Dim rs as recordset rs.movenext

Moveprevious Method
method moves the current record position one record backward (toward the top of the Recordset). Dim rs as recordset rs.moveprevious

BOF(beginning of file)and EOF(End of file) BOF Indicates that the current record position is before the first record in a Recordset object.

EOF Indicates that the current record position is after the last record in a Recordset object.
The BOF and EOF properties return Boolean values.

The BOF property returns True (-1) if the current record position is before the first record and False (0) if the current record position is on or after the first record.
The EOF property returns True if the current record position is after the last

record and False if the current record position is on or before the last record.
If either the BOF or EOF property is True, there is no current record.

BOF(beginning of file)and EOF(End of file)


If we open a Recordset object containing no records, the BOF and EOF properties are set to True . When we open a Recordset object that contains at least one record, the first record is the current record and the BOF and EOF properties are False. If we delete the last remaining record in the Recordset object, the BOF and EOF properties may remain False until we attempt to reposition the current record.

RecordCount Property
Indicates the number of records in a Recordset object. Returns a Long value that indicates the number of records in the Recordset.

Addnew method
Creates a new record for an updatable Recordset object. Use the AddNew method to create and add a new record in the Recordset object named by recordset. Rs.addnew

Update Method
Saves the contents of the copy buffer to an updatable Recordset object. Syntax recordset.Update

Delete Method
deletes the current record in an updatable Recordset object. recordset.Delete

Edit method
Copies the current record from an updatable Recordset object to the copy buffer for subsequent editing. Once you use the Edit method, changes made to the current record's fields are copied to the copy buffer. After you make the desired changes to the record, use the Update method to save your changes

Connect Property
Sets or returns a value that provides information about the source of an open connection, an open database, a database used in a pass-through query, or a linked table. ODBC; DATABASE=database; UID=user; PWD=password; DSN= datasourcename;

Data grid control


Displays and enables data manipulation of a series of rows and columns representing records and fields from a Recordset object. Each cell of a DataGrid control can hold text values, You can specify the current cell in code, the user can change it at run time using the mouse or the arrow keys. Cells can be edited interactively, by typing into the cell, or programmatically. Cells can be selected individually or by row.

AllowAddNew Property
Returns or sets a value indicating whether the user can add new records to the Recordset object underlying a DataGrid control. Syntax dbgrid1.AllowAddNew = true

AllowUpdate Property
Returns or sets a value indicating whether a user can modify any data in the DataGrid control. Syntax dbgrid1.AllowUpdate = true

AllowDelete Property
Returns or sets a value indicating whether the user can delete records from the Recordset object underlying a DataGrid control. Syntax object.AllowDelete [= value]