1. مهمان گرامی، جهت ارسال پست، دانلود و سایر امکانات ویژه کاربران عضو، ثبت نام کنید.
    بستن اطلاعیه

چگونه می توان یک Query را در یک TTable اجرا کرد؟

شروع موضوع توسط para3to ‏11/10/11 در انجمن Delphi

  1. کاربر ارزشمند❤

    تاریخ عضویت:
    ‏17/5/11
    ارسال ها:
    39,257
    تشکر شده:
    47,234
    امتیاز دستاورد:
    170
    چگونه می توان یک Query را در یک TTable اجرا کرد؟
    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