whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

23 Visitors Online


 
...Convert a Query into a Table?
Autor: Wayne Hill
[ Print tip ]  

Tip Rating (5):  
     


//------------------------------------------

unit Unit1;

interface

uses
  
Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;

type
  
TForm1 = class(TForm)
    Button1: TButton;
    Query1: TQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
  private
    
{ Private declarations }
  
public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  
InitQuery: TQuery;
  InitTable: TTable;
  InitBatch: TBatchMove;
begin
  
InitQuery := TQuery.Create(Application);
  with InitQuery do
  begin
    
DatabaseName := 'DBDEMOS';
    Close;
    SQL.Clear;
    SQL.Add('SELECT * ');
    SQL.Add('FROM customer.db');
    SQL.Add('WHERE Country="US"');
    SQL.SaveToFile('mgrInit.sql');
    try
      
Open;
      try // Send the SQL result to c:\temp\INIT.DB
        
InitTable := TTable.Create(Application);
        with InitTable do 
        begin 
          
DatabaseName := 'c:\temp';
          TableName    := 'INIT';
        end;
        InitBatch := TBatchMove.Create(Application);
        with InitBatch do 
        begin
          
Destination := InitTable;
          Source      := InitQuery;
          Mode        := batCopy;
          Execute;
        end;
      finally
        
InitTable.Free;
        InitBatch.Free;
      end;
    except
      
Free;
      Abort;
    end;
    Free;
  end;
end;

end.

//-------------------------


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners