帮忙看一下,下面的代码错在哪里?首先读取配置文件pragram.ini中的数据库配置参数,然后,将一个表的总数分配给edit1.text,还想取一个字段值给edit2.text:begin
try //判断连接的语句,首先读取配置文件-待修改
myinifile:=Tinifile.Create(ExtractFilePath(paramstr(0))+'pragram.ini');
password:=myinifile.readstring('setup','user_pwd','');
user:=myinifile.readstring('setup','user_name','');
database:=myinifile.readstring('setup','srv_data','');
server:=myinifile.readstring('setup','data_source','');
adoconnection1.Close;
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='
+password+';Persist Security Info=True;User ID='
+user+';Initial Catalog='+database
+';Data Source='+server;
adoconnection1.Open;
if adoconnection1.Connected then //判断是否连接成功
begin
application.MessageBox('连接成功!','提示');
adoquery1.SQL.Add('select count(IDH) from rc');
edit1.Text:=adoquery1.Fields[8].AsString;
adoconnection1.Close; //关闭
end;
except
application.MessageBox('数据库连接失败,请确认你已配置好服务器','提示');
frmserver.ShowModal; //这里也提示错的
end;
end;
还有,我想将配置文件内的内容加密后再加入,该怎么改:
begin
myinifile:=Tinifile.Create(ExtractFilePath(paramstr(0))+'pragram.ini');
myinifile.WriteString('setup','Data_Source',edit1.Text);
myinifile.WriteString('setup','srv_data',edit2.Text);
myinifile.WriteString('setup','user_name',edit3.Text);
myinifile.WriteString('setup','user_pwd',edit4.Text);
myinifile.Destroy;
end;
急等!!
try //判断连接的语句,首先读取配置文件-待修改
myinifile:=Tinifile.Create(ExtractFilePath(paramstr(0))+'pragram.ini');
password:=myinifile.readstring('setup','user_pwd','');
user:=myinifile.readstring('setup','user_name','');
database:=myinifile.readstring('setup','srv_data','');
server:=myinifile.readstring('setup','data_source','');
adoconnection1.Close;
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='
+password+';Persist Security Info=True;User ID='
+user+';Initial Catalog='+database
+';Data Source='+server;
adoconnection1.Open;
if adoconnection1.Connected then //判断是否连接成功
begin
application.MessageBox('连接成功!','提示');
adoquery1.SQL.Add('select count(IDH) from rc');
edit1.Text:=adoquery1.Fields[8].AsString;
adoconnection1.Close; //关闭
end;
except
application.MessageBox('数据库连接失败,请确认你已配置好服务器','提示');
frmserver.ShowModal; //这里也提示错的
end;
end;
还有,我想将配置文件内的内容加密后再加入,该怎么改:
begin
myinifile:=Tinifile.Create(ExtractFilePath(paramstr(0))+'pragram.ini');
myinifile.WriteString('setup','Data_Source',edit1.Text);
myinifile.WriteString('setup','srv_data',edit2.Text);
myinifile.WriteString('setup','user_name',edit3.Text);
myinifile.WriteString('setup','user_pwd',edit4.Text);
myinifile.Destroy;
end;
急等!!
解决方案 »
- ***帮忙看看是什么问题,急急急,再线等!!*******
- 急?如何对多个动态创建的Label实现自由拖放?
- 利用宽带开发网络软件的问题
- 大家帮帮我看看这种文件如何读出?
- 请问如何获得TWebBrowser得到的html内容
- 如何对一张bmp进行转换成黑白,并改变(缩小)其尺寸...?
- 哪儿有数据库驱动的象资源管理器那样的TREEVIEW的原代码?
- LISTVIEW的查找问题?
- 如何动态生成组件?急!
- 关于ado控件,我在2000下能正常运行,但在98下就会出现错误,好象跟msado15.dll有关,不知道该怎么办?!
- 帮帮忙阿!!!在线等!
- delphi 有没有 like 比较运算符,没有如何实现 like 功能??
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
edit1.Text:=adoquery1.Fields[0].AsString;
select count(idh) as idh from rc
edit1.text:=adoquery1.fieldbyname('idh').asstring;
把adoconnection1 的close,open改成.Connected:=false;.Connected:=true;
多试几遍啊~
表的总数分配给edit1.text,
edit1.text:=IntToStr(ADOQuery1.RecordCount)
//////////////////////////////////
还想取一个字段值给edit2.text:
应该为:
edit2.text:=ADOQuery1.Fields[0].AsString;/////////////////////////////
application.MessageBox('数据库连接失败,请确认你已配置好服务器','提示');
frmserver.ShowModal; //这里也提示错的应改为:
application.MessageBox('数据库连接失败,请确认你已配置好服务器','提示');
frmserver:=TfrmServer.Create(Application);
frmserver.ShowModal; //这里也提示错的
Project Project1.exe raised exception class EDatabaseError with message'ADOQuery1:field'idh' not found',Use Step or Run to continue.
我不改动任何代码,再编译就提示:数据库连接失败,请确认你已配置好服务器.
var
server:string;
database:string;
password:string;
user:string;
begin
try //判断连接的语句,首先读取配置文件-待修改
myinifile:=Tinifile.Create(ExtractFilePath(paramstr(0))+'setup.ini');
password:=myinifile.readstring('setup','user_pwd','');
user:=myinifile.readstring('setup','user_name','');
database:=myinifile.readstring('setup','srv_data','');
server:=myinifile.readstring('setup','data_source','');
adoconnection1.Close;
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='
+password+';Persist Security Info=True;User ID='
+user+';Initial Catalog='+database
+';Data Source='+server;
adoconnection1.Connected := true;
if adoconnection1.Connected then //判断是否连接成功
begin
application.MessageBox('连接成功!','提示');
adoquery1.SQL.Add('select * from rc');
edit1.Text:=IntToStr(ADOQuery1.RecordCount);
adoconnection1.Connected := false; //关闭
end;
except
application.MessageBox('数据库连接失败,请确认你已配置好服务器','提示');
frmserver:=TfrmServer.Create(Application);
frmserver.ShowModal;
end;
end;end.
结果还是出错:首先提示连接成功,然后跳出编译错误:
标题:Debugger Exception Notification
内容: Project Project1.exe raised exception class EDatabaseError with message'ADOQuery1:Cannot perform this operation on a closed dataset',Process stopped,Use Step or Run to continue.
问题是不是出在别处.
如果想要记录总数的话直接count(*)就可以,idh应该是唯一主键嘛
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Menus,IniFiles;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Button1: TButton;
Label1: TLabel;
MainMenu1: TMainMenu;
N1: TMenuItem;
X1: TMenuItem;
O1: TMenuItem;
S1: TMenuItem;
N2: TMenuItem;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
ADOQuery1: TADOQuery;
procedure X1Click(Sender: TObject);
procedure S1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
myinifile:Tinifile;implementationuses Unit3;{$R *.dfm}procedure TForm1.X1Click(Sender: TObject);
begin
adoconnection1.Close;
close;
end;procedure TForm1.S1Click(Sender: TObject);
begin
frmserver.ShowModal;
end;procedure TForm1.Button1Click(Sender: TObject);
var
server:string;
database:string;
password:string;
user:string;
begin
try //判断连接的语句,首先读取配置文件-待修改
myinifile:=Tinifile.Create(ExtractFilePath(paramstr(0))+'setup.ini');
password:=myinifile.readstring('setup','user_pwd','');
user:=myinifile.readstring('setup','user_name','');
database:=myinifile.readstring('setup','srv_data','');
server:=myinifile.readstring('setup','data_source','');
adoconnection1.Close;
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='
+password+';Persist Security Info=True;User ID='
+user+';Initial Catalog='+database
+';Data Source='+server;
adoconnection1.Connected := true;
if adoconnection1.Connected then //判断是否连接成功
begin
application.MessageBox('连接成功!','提示');
adoquery1.Open;
edit1.Text:=IntToStr(select idh from rc);
edit2.Text := (SELECT T_Eight FROM date WHERE (Date = LEFT(GETDATE(), 10)));
adoconnection1.Connected := false; //关闭
end;
except
application.MessageBox('数据库连接失败,请确认你已配置好服务器','提示');
frmserver:=TfrmServer.Create(Application);
frmserver.ShowModal;
end;
end;
adoquery1.connection:=adoconnection1;