This Is How To Use ADO And FireDAC With Databases
From this article, you will learn the difference between working with databases via the ADO technology and the FireDAC library. Using the right database technology is often a critical part of designing your apps, particularly for Windows application development where there is a very rich array of database choices, not all of which may be hosted on a Windows server. ADO (ActiveX Data Objects) is an app programming interface developed by Microsoft and based on the component technology ActiveX. ADO allows providing data from different sources (relational databases, text files, etc.) in an object-oriented format. FireDAC is a universal data access library that is intended for developing apps for different devices that should be connected to corporate databases. Thanks to a universal and highly-effective architecture, FireDAC ensures high-speed direct native access from Delphi and C++Builder to InterBase, SQLite, MySQL, SQL Server, Oracle, PostgreSQL, DB2, SQL Anywhere, Advantage DB, Firebird, Access, Informix, etc. It’s important to understand that FireDAC is a library. At the same time, ADO is a global technology that ensures access not only to databases but also to texts, documents, tables, and others. In this article, we will consider the connection to MS Access and SQLite databases using both technologies, conduct data sampling and display them on the grid. How to set up a connection to MS Access databases using ADO? To get connected to the MS Access database we need to add a TADOConnection component to the form and tune it. For setting the connection we can move to the ConnectionString property in the object inspector and press the button with three dots “…” or make a double-click on the component. We will see a form where it will be required to choose an option Use Connection String and press a Build button. In the next form, it is necessary to choose Microsoft Jet 4.0 OLE DB Provider and press Next >> We will get to the next tab “Connection”. Here we need to indicate the path to the database file and click OK. Then we need to click OK once again in the window where you can see our Connection String We have only one step left. In the Object Inspector window, it is necessary to switch the LoginPrompt property to False so that after connecting to the database we won’t get a window for inserting login and password. Setting the ADO connection to active If everything is set correctly, we are able to add the Connected property to True and our component will connect to the database. But we won’t do that. The best practice is to get connected to a database during the program launch. For doing that, we can make a double-click on the form and open a code editor where we will see a procedure for a form creation event and add there one code line as you can see in the screenshot below. Then we need to add a TADOQuery component to the form and make all the settings. First of all, we need to set the Connection property. In order to do it, from the dropdown list we need to choose ADOConnection1 which has been set at the previous steps. Now in the SQL property, we will set a question for data sampling. After that let’s go back to the […]
