//动态创建adotable;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
tmpTab:TADOTable;
const
constr='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:/ASP Project/DelphiProject/DBWebService1/post.mdb;Persist Security Info=False';
implementation
{$R *.dfm}
//打开并显示纪录。
procedure TForm1.Button2Click(Sender: TObject);
begin
tmpTab:=TADOTable.Create(self);
tmpTab.ConnectionString:=constr;
tmpTab.TableName:='邮政编码';
DataSource1.DataSet:=tmpTab;
tmpTab.Active:=true;
end;
//关闭。
procedure TForm1.Button1Click(Sender: TObject);
begin
if tmpTab.Active then begin
tmpTab.Active:=false;
tmpTab.Free;
end;
end;
end.