unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Label1: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Query1: TQuery;
    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('EXEC sp_attach_db @dbname = N''newdata'',');
      SQL.Add('@filename1 = N''F:\db2010\newdata.mdf'',');
      SQL.Add('@filename2 = N''F:\db2010\newdata_log.ldf''');
      ExecSQL;
    end;
      Application.MessageBox('数据库附加成功!','提示',64);
  Except
      Application.MessageBox('数据库附加失败!','提示',64);
  end;
end;

end.
posted on 2011-04-11 22:56  巅枫  阅读(632)  评论(0编辑  收藏  举报