如:我我是使用delphi的ADOConnection1连接数据库,连接l个本地的access数据库,但是具体的连接过程我想写到文本文件中,这样使用软件我只需要改文本信息就可以了!拜托了,怎么写啊???????????

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      T: Tstrings;
    begin
      T := Tstringlist.Create;
      T.LoadFromFile('xxxx');
      AdoConnection1.Connected := false;
      AdoConnection1.ConnectionString :=T.Text;
      try
        AdoConnection1.Connected := true;
      except on E: Exception do
        begin
          showmessage(E.Message);
          close;
        end;
      end;
    end;
      

  2.   

    新建一个空文本文件,保存为a.udl
    双击a.udl进行数据库的连接...调用:
    ADOConnection1.ConnectionString:= 'FILE NAME=c:\a.udl';要修改连接信息,双击a.udl进行修改就行了..
      

  3.   

    两位方法都正确,如二楼加try except个人感觉可能会更好
      

  4.   

    用读写INI文件的方法就行了。
    [Connection]
    Connectionstring='连接字符串';
      

  5.   

    读写INI文件要用到TIniFiles

    ...
    var 
      iFile:TIniFile;
      ConnStr:string;//从INI文件中得到的连接字符串..
    iFile:=TiniFile.Create('你的INI文件名');
    try
      ConnStr:=iFile.ReadString('Connection','ConnectionString','');
      //写字符串
      //iFile.WriteString('Connection','ConnectionString',ConnStr;  
    finally
      iFile.Free;
    end;
    ...