unit1.~pas

来自「精彩编程百例75~100 其中有媒体播放器 SQL语言编辑器 ADO方法连接多个」· ~PAS 代码 · 共 67 行

~PAS
67
字号
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    ADOTable1: TADOTable;
    Button1: TButton;
    ListBox1: TListBox;
    Label1: TLabel;
    Edit1: TEdit;
    OpenDialog1: TOpenDialog;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var
access:string;
const
link_str='Provider=%s; Data Source=%s';
dataprovider='microsoft.jet.oledb.4.0';

begin
  Opendialog1.FileName :='*.mdb';
  if Opendialog1.Execute then
  begin
    access:=Opendialog1.FileName ;
    edit1.Text :=access;
    adoconnection1.Connected :=false;
    adoconnection1.ConnectionString :=format(link_str,[dataprovider,access]);
    adoconnection1.Connected :=true;
    adoconnection1.GetTableNames(listbox1.Items);
  end;
end;


procedure TForm1.ListBox1Click(Sender: TObject);
begin
adotable1.Close ;
adotable1.TableName :=listbox1.Items.Strings[listbox1.itemindex];
adotable1.Open ;
end;

end.

⌨️ 快捷键说明

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