unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls, Grids, DBGrids, ADODB;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Button1: TButton;
DataSource1: TDataSource;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ADOQuery: TADOQuery;
ADODataSet: TCustomADODataSet;
begin
ADODataSet := TCustomADODataSet(DBGrid1.DataSource.DataSet);
ADOQuery := TADOQuery.Create(Self);
try
if Assigned(ADODataSet.Connection) then
ADOQuery.Connection := ADODataSet.Connection
else
ADOQuery.ConnectionString := ADODataSet.ConnectionString;
if ADODataSet is TADOTable then
ADOQuery.SQL.Text := 'select * from ' + TADOTable(ADODataSet).TableName
else if ADODataSet is TADOQuery then
ADOQuery.SQL.Text := TADOQuery(ADODataSet).SQL.Text;
ADOQuery.Open;
ShowMessage('Free')
finally
ADOQuery.Free;
end;
end;
end.