DatabaseIntroduction to C++Learn C++

Learn To Develop Powerful C++ Windows Applications To Connect With An InterBase Database

InterBase is a powerful database developed and supported by Idera / Embarcadero, it has a zero-administration, small-footprint database engine that can power your server and even run on your mobile devices as an embedded database. The InterBase 2020 release adds a number of new features, including tablespaces support for InterBase, allowing for better performance on servers with multiple data-storage options. InterBase 2020 is an ultrafast, scalable, embeddable SQL database with commercial grade data security, disaster recovery, and change synchronization abilities.

If you are asking how i can setup Interbase, we explained well before, please check How to Setup a Simple InterBase Database.

In this post, we will connect to this database and the tables created. So your database and table should be the same as explained before or you should arrange some variables in codes given below according to your database setup. 

To use the InterBase database be sure that it is installed before or you can install it from Tools -> Manage Platforms -> Additional Options Tab. Both IBX Components and InterBase 2020 Developer Editions should be checked. The Latest InterBase installation is explained well here if you need more details.

Now let’s create a simple database connection application.

  1. Create a new C++ Builder VCL or FMX Application
  2. Save all units and project files to a new folder
  3. Drag a Button (TButton) and a DBGrid (TDBGrid) from Tools Palette to Form design (Form1)
  4. Drag IBDatabase (TIBDatabase) to Form design to connect Interbase database, 
  5. Drag IBDataSet (TIBDataSet) to Form design to connect to a table of this database with SQL commands,
  6. and Drag DataSource (TDataSource) to Form design to use DataSet as a DataSource in other components, bindings, etc.
  7. Arrange your design as shown below,

8. Double click to IBDatabase1 component that you placed on the Form to establish connection properties as below,

Here, 

– Enter database local location file or select Remote to connect remote IP address.
– Add User Name and Password, Character Set that you use
– and Pres OK with Login Prompt is checked.

You can check your connection by checking the Connected Property of IBDatabase Connection. If you have a problem check the settings above or check your database settings by using IBConsole. You may need to read details about How to Setup a Simple InterBase Database post or the official InterBase Get Started Guide here.

9. To connect a table in this database, select IBDataSet1 component and set Database property to IBDatabase1,

10. Double click to SelectSQL property of IBDataSet1, in this window Command Text Editor select table that you want to connect and write SQL your command, i.e. “select * from table1”,

11. Select DataSource1, and set its DataSet property to DataSet1,

12. Select DBGrid1 and set DataSource Property of Grid1 to DataSource1. So, briefly we build connections between IBDataBase1 -> IBDataSet1 -> IBDataSource1 -> DBGrid1

13. Be sure that you Connected property of IBDatabase is false, to connect manually double click to Button and add lines as below,

14. You can also add queries to IBDataSet as below

This is a very basic connection example, you can find more details officially here, on the docwiki about IBDatabase here and about IBDataSet here

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

Related posts
C++Introduction to C++Learn C++

Learn To Use Break And Continue In Loops With C++

C++Introduction to C++Learn C++

Learn To Define And Use Arrays In C++

C++Learn C++Videos

Learn C++ With Back to Basics: Design Pattern by Mike Shah (CPPCon 2020) Video

C++Introduction to C++Learn C++

Discover Switch Statements in C++

en_USEnglish