what is ADO stand for
ADO is a set of COM components (DLLs) that allow you to access databases as well as e-mail and file systems.
To access any kind of database with ADO, you'll of course need to have ADO/OLE DB libraries. Everything you need to use ADO is probably already on your computer: the files are distributed by Microsoft as a part of Windows 98/2000.
you will probably need to distribute and install the ADO engine. Delphi 5's CD includes an installation of MDAC - Microsoft Data Access Components. You should always make sure to have the latest version, which is available from Microsoft. The Microsoft Data Access Components are the key technologies that enable Universal Data Access. They include ActiveX Data Objects (ADO), OLE DB, and Open Database Connectivity (ODBC).
ADO Objects
These objects provide the functionality to connect to data sources, query and update record sets, and report errors.
some of the Objects ADO works with:
The Connection object represents a connection to the data source with the connection strings. In BDE/Delphi a Connection object is a combination of the Database and Session components.
The Command object enables us to operate on a data source. Ir represents a command (also known as a query or statement) that can be processed to add, delete, query or update the data in a database.
The Recordset object is a result of a Query command. You can think of a Recordset as a Delphi Table or Query component. Each row that the Recordset returns consists of multiple Field objects.
In order to be able to access data in an Access database with ADO and Delphi, you must add at least three data aware components to our project. First, the DBGrid on the DataControls component page - used to browse through the records retrieved from a table or by a query. Second, the DataSource (DataAccess Page) used to provide a link between a dataset and DBGrid component on a form that enable display, navigation, and editing of the data underlying the dataset. And finally the ADOTable (ADO page) that represents a table retrieved from an ADO data store.
Link between components
In order to display some data from a database we have to link all three components together. Using the Object Inspector, set the following:
DBGrid1.DataSource = DataSource1
DataSource1.DataSet = ADOTable1
to really get the data from our database we have to build a ConnectionString. This string indicates where the database is physically stored and how we are accessing it.
Press the Build button - this pops up the Data Link Properties dialog. This dialog has 4 pages. The Provider tab allows you to specify the provider - select the Microsoft Jet 4.0 OLE DB Provider. The Next button leads us to the second page: Connection. Select the ellipsis button to browse for our database (AboutDelphi.mdb). Press the Test Connection button to see if the connection is successful
the connection string is stored in the ConnectionString property of the ADTTable component. The connection string should look something like:
Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\!gajba\About\aboutdelphi.mdb;
Persist Security Info=False
Every (ADO) data-aware Delphi form, in general, consist of
· several data-aware controls (Data Controls tab) that create a visual user interface (the look of the data form).
· one DataSource component (Data Access tab) that represents an interface between a dataset component and data-aware controls on a form.
· one or more dataset components (ADO tab) that provide access to the data residing in a database table or query.
· a connection component (ADO tab) that points all the dataset components to a specific data store.
Data Source
Simply put, the DataSource component provides a mechanism to hook dataset components to the visual data-aware components that display the data. You generally will need one datasource component for each dataset component to present a link to one or more data-aware controls.
Datasets
To create an ADO based application, Delphi provides us with four dataset components: TAdoDataSet, TAdoTable, TAdoQuery and TAdoStoredProc. All of the components are designed to retrieve, present and modify the data. All those components can connect directly (as like in the previous chapter's examples) to an ADO data store (such as data in an Access database) through it's ConnectionString property or they can chare a single connection. When connecting through a TAdoConnection the Connection specifies an ADO connection object to use to connect to an ADO data store.
ADO Connection
The ADOConnection component is used to establish a connection with an ADO data store. Although each ADO dataset component can directly connect to a database, we will typically want to use the ADOConnection component since the component provides methods and properties for activating the connection, accessing the ADO data store directly and for working with transactions. In order to connect to a specific database, we use the ConnectionString property.
Now, when we know the theory it's time to see some action. The next step is to build a data form. Before we move on, it'll be a good idea to open the database with Access and add some "dummy" data (3-4 records) to a database just to have some operational data.
There are two different ways of creating forms with access to a data from a database. The first way is to use the Database Form Expert. Unfortunately, the Database Form Expert works only with the BDE-aware set of dataset components. The second way is to place and connect all the data components by hand.
Defining the User Interface
We'll build our data browsing form in three steps. First step is to define the user interface for the form. Next, the data access components are added and configured. In the third and final step, the data-aware controls are added
No comments:
Post a Comment