0% found this document useful (0 votes)
131 views

VB-UNIT III-Data Access Options' With You

This document discusses data access options in Visual Basic, including Data Access Objects (DAO), ODBC Direct, Remote Data Objects (RDO), Open Database Connectivity (ODBC), Visual Basic Library for SQL Server (VBSQL), and Active Data Objects (ADO). It focuses on DAO and describes the hierarchy and usage of various DAO objects like the DBEngine, Workspace, Database, TableDef, QueryDef, Recordset, Field, Index, and Parameter objects for accessing and manipulating data in a database.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

VB-UNIT III-Data Access Options' With You

This document discusses data access options in Visual Basic, including Data Access Objects (DAO), ODBC Direct, Remote Data Objects (RDO), Open Database Connectivity (ODBC), Visual Basic Library for SQL Server (VBSQL), and Active Data Objects (ADO). It focuses on DAO and describes the hierarchy and usage of various DAO objects like the DBEngine, Workspace, Database, TableDef, QueryDef, Recordset, Field, Index, and Parameter objects for accessing and manipulating data in a database.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

VISUAL BASIC

UNIT – III
ODBC AND DATA ACCESS OBJECTS

I. DATA ACCESS OPTIONS


• VB provides a variety of options to access remote client/server database.
• They are,
i. Data Access Objects (DAO) – It communicates with data sources
through the JET database engine.
ii. Data Control – It binds data-aware controls to Microsoft Access
and other ODBC data sources.
iii. ODBC Direct – It allows accessing of ODBC data sources through
the RDO with DAO objects, bypassing the JET database engine.
iv. Remote Data Objects (RDO) – It provides a framework for using
code to create and manipulate components of a remote ODBC
database system.
v. Open Database Connectivity (ODBC) – This is an API call
interface to the open Database Connectivity libraries and drivers to
provide data access to Oracle and other databases that provide an
ODBC driver.
vi. Visual Basic Library for SQL Server (VBSQL) – It is an
implementation of the DB library API specifically designed to
provide access to an SQL server through a VB application.
vii. Active Data Objects (ADO) – This is a programming model that
eliminates the need to choose from among DAO and RDO and all
other data access methods.
Data Access Objects

A Data Access Object is a collection of object classes that model


the structure of a relational database system.

They provide properties and methods that allow the user to


accomplish all the operations needed to manage such a system,
including features for creating databases, defining tables, navigating
and querying a database.

VB supports Data Access Objects such as

• DBEngine
• Workspace
• Database
• TableDef
• Field
• Index
• Recordset Objects.

The DBEngine

- Is the top-level database object and corresponds to the Jet database engine.
- This object Used to set database engine system parameters and default
workspace.

The Workspace

- The workspace object is used to support simultaneous transactions and it


acts as a container for open databases.
- A default Workspace object Workspace(0) is created when the Data Access
Objects are referenced in the language at run time.
- The default workspace is always available and can never be closed or
removed from the collection.

Data Access Objects Hierarchy

The Database

- Corresponds to a jet native or external database or a direct ODBC


connection.
- Used to define the database’s table, relations and stored queries and to open
Reordset objects.
The TableDef

- Corresponds to a stored table definition.


- Each represents the definition of a table in the current database or an
attached table in the external database.

The QueryDef

- is a stored query definition, which is a precompiled SQL statement.

The Recordset

- corresponds to a cursored view into a database table or the results of a


query.
- A cursored view is one that stores rows of data in buffer and points to one
row of data at a time called current record.
- the cursor may be pointed to any row of data using Move, Seek or Find
methods.

The Field object

- corresponds to a column of data type and set of properties.

- TableDef, QueryDef and Recordset objects have a collection of Field objects.

- the collection of Field objects associated with a Recordset cursor describes a


single row of data.

The Index Object

- is a stored index associated with Table Def Object or table type Recorset Object

- setting the index allows the user to quickly re-order the records in a table.
The Parameter Object

- represents a parameter associated with a QueryDef Object created from a


parameter query.

- A parameter’s collection contains all the parameter objects of a QueryDef object.

The User Object

- is used to define and enforce database security.

- the DBEngine Object supports a set of users collection.

- The users collection contains all stored User objects of a Workspce or group
account.

A Group

- is a collection of users with similar access rights.

- the DBEngine Object supports a collection of system groups.

- Each user in the group inherits the permissions to access the objects that the
group can access.

A Relation Object

- represents a relationship between fields in tables or queries.

- A relations collection contains stored relations objects of a database object.

A Property Object

- represents a built-in characteristic or a user-defined characteristic of a data access


objects.
A Document Object

- includes information about one instance of a type of object.

- the object can be a database, saved table, query, or relationship.

A Container Object

- holds information describing the objects that are grouped into that container.

- Acontainers collection contains all container objects that are defined in a


database.

Accessing and Navigating Databases

- In order to work with data access objects, a reference has to be set to the
appropriate DAO library. There are 2 DAO libraries supported by VB 6.0. They
are

- Microsoft DAO 3.51 Object Library

- Microsoft DAO 2.5/3.51 Compatibility Layer

To set reference to the DAO type library the following sequence has to be
followed:

- Select Reference from the project menu

- Select the DAO 3.51 Object Library

- Click on OK
Opening a Database

- To open an existing database, the OpenDatabase method of the Workspace


object is used.

Syntax:

OpenDatabase(dbname, [options],[readonly],[connect])

The following code opens the employee_details database.

Dim db as Database

Set db = OpenDatabase(“emloyee_details”)

db- is a variable that represents the Database object. Specify the database for
exclusive use,

Set db = OpenDatabase(“employee_details”, True)

For read only mode

Set db = OpenDatabase(“employee_details”, False, True)

True – provide only a read access on the database


Recordset

- A Recordset is an object that contains a set of records from the database.

- There are 5 major types of Recordset objects

i) Table Type Recordset

- It is a set of records that represents a single table which can be used to add,
change or delete records.

- They are the fastest type of Recordsets

ii) Dynaset-Type Recordset

- It is a set of records that represents a table, or attached tables, or the results of


queries containing fields from one or more tables.

- It enables us to update data from more than one table.

iii) Snapshot Type Recordset

- It refer to any table, attached table or query.

- It cannot be updated and does not reflect any changes made by the users.

iv) Dynamic Type Recordset

- This type represents a query result set from one or more base tables in which we
can add, change, or delete records from a row-returning query.

v) Forward only type Recordset

- It is identical to snapshot Recordset except that we can only scroll forward


through its records.
Creating a Recordset

- The OpenRecordset method is used to open a Recordset and create a Recordset


variable.

Ex:

Dim rs as Recordset

Set rs = db.OpenRecordset(“employee”,dbOpentable, dbReadOnly)

Where

db – is the variable that represents the database object.

dbOpenTable – specifies the type of Recordset to be created.

Navigating a Recordset

- After creating a Recordset object, various Move methods can be used to navigate
through the records in a Recordset.

- The MoveFirst method moves to the first row in the Recordset

- The MoveNext method moves to the next row in the Recordset

- The MovePrevious method moves to the previous row in the Recordset

- The MoveLast method moves to the last row in the Recordset


Using BOF and EOF to Navigate through Recordsets

- the Recordset object provides 2 properties to the user to know when he has
moved to the beginning or the end of the recordset.

- The EOF(End of File) property is True when the user moves beyond the
last record in the recordset.

- The BOF(Beginning of File) property is True when the user has moved to a
position before the first record in the recordset.

Modifying and Deleting Records

- to manipulate record in a recordset, the following methods are used,

Edit Method – the user can edit the current record using the Edit method.
The update method is used to save the necessary changes made to the record.

AddNew Method – is used to create a new record in the Recordset

Delete Method – used to delete an existing record in the dynaset or table


type recordset. The Jet engine deletes the current record without warning when the
Delete method is used.

Finding Records

- used to locate a record in a dynaset or snapshot type Recordset. Like

FindFirst method – finds the first record satisfying the specified criteria.

FindLast method – finds the last record satisfying the specified criteria.
FindNext method – finds the next record satisfying the specified criteria,
searching forward from the current record.

FindPrevious method – finds the previous record satisfying the specified


criteria, searching backward from the current record.

Indexed searches using the Seek Method

- The Seek method can be used to locate a record in a table type Recordset.

- It performs an indexed search for the first occurrence of the record that matches
the indexed criteria.

- Dynasets and Snapshots cannot use the Seek method

Manipulating Stored Queries using the QueryDef Object

- The QueryDef object contains information about a stored SQL query.

- faster than SQL queries

- because VB must go through a processing step before executing a SQL query.

- stored queries are stored in their processed format


Creating Parameterized Queries Using the Parameter Object

- Parameter query can be created by using the parameters collection of QueryDef


object.

- A value must be supplied for the parameter in order to run the query.
TableDef Data Object

- TableDef is a collection of Table objects that contain detailed definition about


each data table in the database. There are 5 methods available
Modifying and Deleting Existing Tables

- New fields can be added or existing fields can be deleted using the Append or
Delete methods respectively on the Tabledef object.

Creating a Table in Oracle using SQL*Plus

- A table is created in SQL*Plus using the following syntax:

CREATE TABLE <table name>

(column_name1 datatype, column_name2 datatype, ……)


Inserting Values in a Table

- to add rows to a table

Syntax

INSERT into <table_name> VALUES <data_list>

- The data entered in the table should match the order of the columns as they
appear in the table.

You might also like