Delphi database programming tutorial (7)

zhaozj2021-02-16  53

Chapter 4 Data Browse and Navigation

The first quarter settings and connections

Welcome to the fourth chapter of the free DB Delphi tutorial! Up to now, this tutorial explains how to connect to the Access database and how to display graphical data in the database table. In the previous chapter, we discussed some "advanced" database programming techniques (translators: relative to beginners) - now let us return to "for beginners".

This time, you will learn how to establish a form that can be browsed in the database table.

All examples of the previous chapter introduced several data enabled (ADOTABLE, DBGRID ...) have no sufficient explanation that each component is designed to implement, how to connect all data components together. This chapter will be described.

Work together (Working together ...)

Developing an ADO-based Delphi database application, the components on the component panel of the component panel, the components on the ADO page and the Data Access page allow us to read and write information from the database.

Data-aware (ADO) Delphi form, usually contains:

Several data visual components (Data Controls page) for creating a user interface (external table of data form).

A DataSource component (Data Access page), as an excuse of the data set component and data visual control on the form.

One or more data set components (page) provide access to data in database tables or query results.

A connection component (page), pointing all the data set components to the specified database.

Data Control (Data Controls)

Delphi's data visual components are typically located at the Standard page, but there are also some components that are improved to display and manipulate the contents of the data set (table or query). The selection of the control is determined by how we want to display information and how to browse (operation-add or edit) data sets. For example, DbEdit and DBMEMO are used to display a single record of the dataset. On the other hand, DBGRID is usually used to display the content of the entire data set. Since all data visual controls are the "copy" of the standard Windows control - with many additional properties, establish a database application with a certain function should also be a very familiar task (translator plus: The usual Windows task is compared.). All data visual components share the same attribute: Data Source.

Data Source

Simply put, DataSource components provide a mechanism that connects data set components and data visual components of display data. Typically, you need a data source component for each data set component to connect to one or more data visual controls.

Datasets

To create an ADO-based application, Delphi provides four dataset components: Tadodataset, Tadotable, TadoQuery, and TadoStoredproc. All components are used to obtain, represent, and change data. All components can be connected directly to the ADO database (like the data database of the Access database), or they can share a connection. When connected to the Tadoconnection component, the connection specifies an ADO connection object to the ADO database.

ADO connection

The AdoConnection component is used to establish a connection to the ADO database. Although each ADO data set component can connect directly to the database, we will still use the Adoconnection component because the component provides methods and properties to activate the connection, directly access the ADO database, and process transactions. In order to connect to the specified database, we use the Connectionstring attribute.

Now, we know related theories, it is time to act! A data sheet will be created next. Before starting, use Access to open the database and add some "dumns" data to the database for future data operations, which is a good idea.

转载请注明原文地址:https://www.9cbs.com/read-24477.html

New Post(0)