Delphi如何用ADOconnection+Ini动态连接SQL Server2000数据库

来源:互联网 发布:java添加按钮监听器 编辑:程序博客网 时间:2024/04/29 07:30

现有app.ini文件如下:
[database]
dbname=test
serverip=.
user=sa
password=
问题1:serverip=.  .代表默认的SQL Server2000?
目标: 通过单击一个按钮,实现显示数据表的内容
procedure TForm1.Button1Click(Sender: TObject);
var
myinifile:Tinifile;
filename,v_u,v_i,v_d,v_p:string;
begin
with ADOQuery1 do
begin
Filename:=ExtractFilePath(Paramstr(0))+'app.ini';
myinifile:=Tinifile.Create(Filename);

v_u:=myinifile.readstring('database','user','');
v_i:=myinifile.readstring('database','serverip','');
v_d:=myinifile.readstring('database','dbname','');
v_p:=myinifile.readstring('database','password','');

adoconnection1.Connected:=false;
adoconnection1.Close;
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=true;User ID='v_u)+';Initial Catalog='+v_i+';Data Source='+v_d+';password='+v_p;
adoconnection1.Connected:=true;

adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select* from test');
adoquery1.Open;
end;
end;
麻烦各位朋友帮我看看