RT 不用每次打开程序都要设置ADOConneciton,
我ADOConneciton的设置是用ADOConnection1.ConnectionString:='XXedit1.textXX'来设置的;
我ADOConneciton的设置是用ADOConnection1.ConnectionString:='XXedit1.textXX'来设置的;
解决方案 »
- 求救,delphi7根据x=3,y=4形成一个lable控件数组,然后给控件的caption赋值。
- 关于用WinSock发送邮件的问题
- 怎样向局域网中的所有电脑传送文件(是单方的)
- fast report的字段显示问题
- 庆祝hsmserver(撒哈拉之雨的悲伤)大哥升**,大家一起高兴,散分!
- 关于数据流的方法
- 请问:怎么提高 Sql Server查询速度
- 求交点,你知道算法么????
- 老大们:::谁知道Serv-U怎么使用呀???看了一大堆使用文章,还是不会用:((((
- 一起看日出
- ListBox1.ItemIndex等于TreeView1里面的什么?
- 怎样进行数据库查询?[太简单了,你一定能答上]
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, Buttons, StdCtrls, Inifiles;type
TForm1 = class(TForm)
ADOConn: TADOConnection;
ADOCommand1: TADOCommand;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
SpeedButton1: TSpeedButton;
Label5: TLabel;
Label4: TLabel;
Label3: TLabel;
Label2: TLabel;
Label1: TLabel;
edtUser: TEdit;
edtTableName: TComboBox;
edtServerName: TEdit;
edtPasswd: TEdit;
edtServerIP: TEdit;
btnTest: TBitBtn;
DataSource1: TDataSource;
Button1: TButton;
procedure SpeedButton1Click(Sender: TObject);
procedure btnTestClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure edtServerIPChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
myinifile:TInifile;implementation{$R *.dfm}procedure TForm1.SpeedButton1Click(Sender: TObject);
var
strCon: string;
begin
strCon := '';
ADOConn.Connected := False;
strCon := PromptDataSource(Handle, ADOConn.ConnectionString);
if strCon <> '' then
begin
ADOConn.ConnectionString := strCon;
ADOConn.Connected := True;
edtServerIP.Text := ADOConn.Properties['Data Source'].Value;
edtServerName.Text := ADOConn.Properties['Initial Catalog'].Value;
edtUser.Text := ADOConn.Properties['User ID'].Value;
edtPasswd.Text := ADOConn.Properties['Password'].Value;
end;
end;procedure TForm1.btnTestClick(Sender: TObject);
begin
try
if not adoconn.connected then adoconn.connected := true;
adoquery1.close; adoquery1.sql.clear;
adoquery1.sql.add('select * from lzz');
adoquery1.open;
Application.MessageBox('已连接上数据库,测试成功! ', '提示信息', MB_OK or MB_ICONINFORMATION);
except
adoconn.connected:= false;
Application.MessageBox('无法连接上数据库,测试失败! ', '提示信息', MB_OK or MB_ICONERROR); end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ADOconn.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;'+
'Persist Security Info=False;Initial Catalog=lzz;Data Source='+edtServerIP.Text+';'+
'Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation '+
'ID=PC-200905191449;Use Encryption for Data=False;Tag with column collation when possible=False';
end;procedure TForm1.edtServerIPChange(Sender: TObject);
begin
if edtServerIP.Text <> '' then
button1.Enabled:=true;
end;function CompToStr(Component:TComponent):string;
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s:string;
begin
BinStream:=TMemoryStream.Create;
try
StrStream:=TStringStream.Create(s);
try
BinStream.WriteComponent(Component);
BinStream.Seek(0,soFromBeginning);
ObjectBinaryToText(BinStream,StrStream);
StrStream.Seek(0,soFromBeginning);
Result:= StrStream.DataString;
finally
StrStream.Free;
end;
finally
BinStream.Free
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
FileName:string;
begin
// 获取当前程序所在路径
FileName:='c:\myini.ini';
// 创建myinifile对象,并创建或打开myini.ini文件
myinifile:=TInifile.Create(FileName);
// 读取值
ADOConn.ConnectionString:= myinifile.ReadString('form1',''ADOConn''); //到这就出错了
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// 在程序关闭时写入myini.ini文件
myinifile.WriteString('form1','ADOConn',ADOConn.ConnectionString);
// 释放myinifile对象
myinifile.Destroy;
end;end.可是到
myinifile.Readstring('小节名','关键字',缺省值);一定要三项都填才行