unit1.~pas

来自「Delphi数据库编程」· ~PAS 代码 · 共 63 行

~PAS
63
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ListBox1: TListBox;
    ListBox2: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    procedure ListBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListBox1Click(Sender: TObject);
  var
    FieldLists:Tstrings;
    Tabname:string;
begin
   FieldLists:=TstringList.Create;
   TabName:=listbox1.Items[ListBox1.itemindex];
   ADOConnection1.GetFieldNames(tabname,Fieldlists);
   ListBox2.Items :=FieldLists;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
   TableList:Tstrings;
   CurDir:String;
 begin
   GetDir(0,CurDir);
   ADOConnection1.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Curdir+'\教学.mdb;Persist Security Info=False';
   ADOConnection1.open;
   TableList:=TstringList.Create ;
   ADOConnection1.GetTableNames(tableList);
   ListBox1.Items :=TableList;
   ListBox1.Refresh ;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ADOConnection1.Close ;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?