回 帖 发 新 帖 刷新版面

主题:delphi连接数据库ini读取问题

我做了个登陆界面,想运行程序时系统按照ini读取连接参数,ini放在d盘,由于是菜鸟,一直没有调试出来,下面是源代码,望前辈赐教:


   unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, IniFiles,XPMan;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    Edit1: TEdit;
    Edit2: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    XPManifest1: TXPManifest;
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    IniFile:TIniFile;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
  Var
   DataSource,InitialCatalog,UserId,Password : string;

 //Filename:=ExtractFilePath(Paramstr(0))+’d:\connection.ini’;
 IniFile:=TInifile.Create(’d:\connection.ini’);




begin
    DataSource:=INI.Readstring('connection','Data Source','');
    InitialCatalog:=INI.Readstring('connection','Initial Catalog','');
    UserId:=INI.Readstring('connection','user id','');
    Password:=INI.Readstring('connection','password','');

    ADOConnection1.ConnectionString :='Provider=SQLOLEDB.1;Persist Security Info=true;User ;password='+Password+';Initial Catalog='+InitialCatalog+';data source='+DataSource;

    ADOConnection1.Connected := True;
    ADOConnection1.loginprompt :=false;

    ini.Free;


end;

end.

回复列表 (共1个回复)

沙发


读取ini参数的目的是动态连接数据库

我来回复

您尚未登录,请登录后再回复。点此登录或注册