这个例子要注意建立数据源(.mdb),还有就是使用table组件的tablename属性
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, Grids, DBGrids;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
Database1: TDatabase;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Database1.Params.Add('username=sa');
Database1.Params.Add('password=');
Database1.LoginPrompt:=False; //不显示登陆对话框
Database1.DatabaseName:='QP';
Database1.AliasName:='QP';
TABLE1. ACTIVE:=TRUE;
end;
end.