1. Technology
Send to a Friend via Email

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/library/weekly/aa071205a.htm

was emailed to:

Thanks for sharing About.com with others!

Access / SQL Server Database Explorer with full Delphi source code
The ADPDBExplorer (About Delphi Programming Database Explorer) application allows you to connect to a Microsoft Access (MDB) database and/or SQL Server / MSDE database to explore a database structure, insert, edit or delete data.
 More of this Feature
• Download ADPDBExplorer executable (~ 550 KB)
• Download Delphi source
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• Database Programming Course
• Free source Delphi applications

The ADPDBExplorer (About Delphi Programming Database Explorer) application allows you to connect to a Microsoft Access (MDB) database and/or SQL Server / MSDE database to explore a database structure, insert, edit or delete data. Features also include running "free-hand" queries (select, insert, update, etc.) against the database using a simple query builder. A simple master-details relationships builder allows displaying and operating on joined tables.

This application is build on the grounds of the "Database Programming Course". The source code provides an excellent introduction to the dbGo (ADO) object model in Delphi database applications.

ADPDBExplorer
ADPDBExplorer running
Connecting to a database
ADPDBExplorer can connect to and manage MS Access and MS SQL Server databases.

The "Open Access (MDB)" menu item (from the Database main menu) is used to bring up an "Open file" type of dialog that lets a user pick a MDB database to operate on.

The "Open SQL Server" item calls a custom connection dialog for a SQL server database (mimics the standard Windows OLE DB Data Link Properties dialog). The explanation of the code used can be found in the article: "Enumerating SQL Servers, Retrieving databases from a SQL Server"

ADPDBExplorer provides a most recently used list (MRU) of the databases accessed. The MRU list allows for quick selection of an Access database that was recently opened without having to select an Open menu item and search to locate a specific lately accessed database. The free source TadpMRU component is used. Note: the MRU list only stores recently used MDB (Access) databases.

ADPDBExplorer Connectivity

Examining table data
When you connect to a database, a tree view will be populated with all table names from the active database. To open a table in "edit" mode, simply click on a table name. A form opens hosting a DBNavigator and a DBGrid ready to be used to insert, edit, delete or move through table records.

Database objects tree view

Master-Detail and "Free-hand" Queries
By selecting the "Query" item from the "Misc" tree view group, a new form will be created enabling you to specify and execute any valid SQL statement (either returning a dataset or just executing an UPDATE statement, for example).

Note: while you can execute DDL statements (like CREATE TABLE), ADPDBExplorer was not designed to be used to alter the structure of tables (views, stored procedures, etc.).

The "Master-Detail" item opens a more complex form where you can specify what fields from two tables form a master-detail relationship.

Here's an example:

  1. Connect to the sample DBDemos.MDB database located in the "c:\Program Files\Common Files\Borland Shared\Data" folder (on a default installation)
  2. Select the "Master detail" item from the tree view
  3. Select "customer" for the master table
  4. Select "orders" for the child table
  5. Select "CustNo" field from both the "Master fields" and "Child fields" list box
  6. hit the "[>]" button
  7. Display the records by clicking on the "Refresh" button
The form is displaying all the records from the "customer" table in the top grid, and only the related records from the "orders" table.

ADPDBExplorer: Master Detail View

Free (source) download
ADPDBExplorer is an operational application, however, there are many areas where it can be improved. You can download the full source code to learn and enhance the application with your ideas, or simply download the executable version if you are in "hurry" and have an Access or SQL Server database you need to operate on (no installation is required, simply run the ADPDBExplorer.EXE file).

Paradox, DBase, mySQL, myDatabase?
If your database is not Access or SQL Server, you can easily alter the application to connect and operate on any other database. You only need to know the correct connection string for the ADOConnection object.

If you need any help with the code, be sure to post your questions on the Delphi Programming Forum.

©2014 About.com. All rights reserved.