unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Memo1: TMemo;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Database1: TDatabase;
    Query1: TQuery;
    procedure FormCreate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  try
    with Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('create table 教师表');
      SQL.Add('(教师编号 varchar(20) not null,constraint aaa primary key(教师编号),教师姓名 varchar(20),科室 varchar(20),年龄 int,工资 int)');
      ExecSQL;
    end;
    Application.MessageBox('索引创建成功!','提示',64);
  Except
    Application.MessageBox('系统错误!','提示',64);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Query1.DatabaseName:='DB2010';
  Database1.AliasName:='DB2010';
  Database1.params.Add('user name=sa');
  Database1.Params.Add('password=');
end;

end.
posted on 2011-03-28 19:26  巅枫  阅读(291)  评论(0编辑  收藏  举报