Uconn.pas
上传用户:ddd699
上传日期:2010-01-18
资源大小:636k
文件大小:2k
- unit Uconn;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids, DBCtrls, dbcgrids;
- type
- TftmConn = class(TForm)
- Memo1: TMemo;
- connDate: TADOConnection;
- ADOQuery: TADOQuery;
- DataSource1: TDataSource;
- BtnConn: TButton;
- btnSQLOpen: TButton;
- btnClose: TButton;
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- GroupBox3: TGroupBox;
- GroupBox4: TGroupBox;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- txtDS: TEdit;
- txtDB: TEdit;
- txtName: TEdit;
- txtPWD: TEdit;
- DBGrid1: TDBGrid;
- procedure BtnConnClick(Sender: TObject);
- procedure btnSQLOpenClick(Sender: TObject);
- procedure btnCloseClick(Sender: TObject);
- private
- { Private declarations }
- public
- aConStr :string;{ Public declarations }
- end;
- var
- ftmConn: TftmConn;
- implementation
- {$R *.dfm}
- procedure TftmConn.BtnConnClick(Sender: TObject);
- begin
- //aConStr :='Provider=SQLOLEDB.1;Password=12345;Persist Security Info=False;User ID=sa;Initial Catalog=心理咨询;Data Source=DECAY';//“心理咨询”为数据库名
- aConStr :='Provider=SQLOLEDB.1;Password='+txtPWD.Text+';Persist Security Info=False;User ID='+txtName.Text+';Initial Catalog='+txtDB.Text+';Data Source='+txtDS.Text;//“心理咨询”为数据库名
- //aConStr := PromptDataSource(Application.Handle ,'');
- connDate.connectionString:=aConStr;
- try
- connDate.Connected:=true;
- // memo1.Lines.Text:= aConStr;
- showmessage(aConStr);
- except
- showmessage('数据源连接出错,请重新建立数据库连接.');
- end;
- end;
- procedure TftmConn.btnSQLOpenClick(Sender: TObject);
- begin
- //try
- // connDate.Connected:=true;
- try
- adoquery.Close;
- adoquery.SQL:=memo1.Lines;
- //showmessage(memo1.Lines.Text);
- adoquery.Prepared;
- adoquery.ExecSQL;
- adoquery.Active:=true;
- //showmessage('ok');
- except
- showmessage('SQL语法出错,请检查语法.');
- end;
- //except
- //showmessage('数据源连接出错,请先建立数据库连接.');
- //end;
- end;
- procedure TftmConn.btnCloseClick(Sender: TObject);
- begin
- application.Terminate;
- end;
- end.