IBDAC

Retrieving Data From Tables

This tutorial describes how to retrieve data from a table using the TIBCQuery and TIBCTable components.

  1. Requirements
  2. General Information
  3. TIBCQuery
  4. TIBCTable
  5. Additional Information

Requirements

This tutorial assumes that you have already connected to the server (see Connecting to InterBase and Firebird), created the necessary database objects (see Creating Database Objects), and inserted data into tables (see Inserting Data Into Tables). To retrieve data at runtime, add the IBC unit to the uses clause for Delphi or include the IBC.hpp header file for C++ Builder.

General Information

IBDAC provides the TIBCQuery and TIBCTable components for retrieving data from a table. This tutorial shows you how to retrieve data from the dept table.

TIBCQuery

The following code demonstrates how to retrieve data from the dept table using TIBCQuery:

Delphi

var
  IBCQuery1: TIBCQuery;
begin
  IBCQuery1 := TIBCQuery.Create(nil);
  try
    // IBCConnection1 was set up earlier
    IBCQuery1.Connection := IBCConnection1; 
    // adds a statement to retrieve data
    IBCQuery1.SQL.Text := 'SELECT * FROM dept';
    // opens the dataset
    IBCQuery1.Open;
    // shows the number of records in the dataset
    ShowMessage(IntToStr(IBCQuery1.RecordCount));
  finally
    IBCQuery1.Free;
  end;
end;

C++Builder

TIBCQuery* IBCQuery1 = new TIBCQuery(NULL);
try {
    // IBCConnection1 was set up earlier
    IBCQuery1->Connection = IBCConnection1;
    // adds a statement to retrieve data
    IBCQuery1->SQL->Text = "SELECT * FROM dept";
    // opens the dataset
    IBCQuery1->Open();
    // shows the number of records in the dataset
    ShowMessage(IntToStr(IBCQuery1->RecordCount)); 
}
__finally {
    IBCQuery1->Free();
}

TIBCTable

The following code demonstrates how to retrieve data from the dept table using TIBCTable:

Delphi

var
  IBCTable1: TIBCTable;
begin
  IBCTable1 := TIBCTable.Create(nil);
  try
    // IBCConnection1 was set up earlier
    IBCTable1.Connection := IBCConnection1; 
    // indicates the name of the table
    IBCTable1.TableName := 'dept';
    // opens the dataset
    IBCTable1.Open;
    // shows the number of records in the dataset
    ShowMessage(IntToStr(IBCTable1.RecordCount)); 
  finally
    IBCTable1.Free;
  end;
end;

C++Builder

TIBCTable* IBCTable1 = new TIBCTable(NULL);
try {
    // IBCConnection1 was set up earlier
    IBCTable1->Connection = IBCConnection1; 
    // indicates the name of the table
    IBCTable1->TableName = "dept";
    // opens the dataset
    IBCTable1->Open();
    // shows the number of records in the dataset
    ShowMessage(IntToStr(IBCTable1->RecordCount));
}
__finally {
    IBCTable1->Free();
}

Additional Information

It is also possible to use stored procedures to delete data, in which case all data manipulation logic is defined on the server. See Using Stored Procedures for more information.

© 1997-2022 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback