Delphi Database, Delphi Components from ComponentAce
Products Download Order Contact us
Executing Queries
Previous  Top  Next



Executing a query

Use Absolute Database DBManager utility (...\AbsoluteDatabase\Ultils\Bin\DBManager.exe), if you would like to execute SQL query manually.

To execute an SQL query from your application, you can perform the following steps:

1.Place TABSDatabase and TABSQuery components from the Absolute DB page of the Component palette to a data module or on a form, if you have not already done it.  
2.Set up TABSDatabase component. Set the TABSDatabase.DatabaseName of the component to a unique value that will be used later to identify the database. Set the TABSDatabase.DatabaseFileName property to the name of the existing or new database file, if you have not already done it.  
3.Set up TABSQuery component. Set the TABSQuery.DatabaseName property from the drop-down list of available TABSDatabase components. Assign the query command(s) to the TABSQuery.SQL property. If you'd like a query to return a modifiable records set, set TABSQuery.RequestLive property to True.  
4.Connect to a database (optional).  
5. Execute / Open a query. You can execute a query in two ways,
·If a query returns records set, i.e. SELECT command, set the Active property of the query to True, either at design time in the Object Inspector, or in code at runtime: ABSQuery1.Active := True; or call the Open method for the query at runtime, ABSQuery1.Open;  
·If a query doesn't return records, i.e. INSERT, UPDATE, etc., call the ExecSQL method for the query at runtime, ABSQuery1.ExecSQL;  

Example:

  {set up database component}
  ABSDatabase1.DatabaseName := 'emp_db'
;
  ABSDatabase1.DatabaseFileName := 'c:\data\employee_db.abs'
;

  {set up query component}

  ABSQuery1.DatabaseName := 'emp_db'
;
  ABSQuery1.SQL.Text := 'select * from employee'
;
  ABSQuery1.RequestLive := True;
   
  if (not ABSDatabase1.Exists) then
    raise Exception.Create('Database file does not exist'
);

  {execute and open query}

  ABSQuery1.Open;

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Dec 21, 2024