我在form1中有:(ADOQueryfilelist : TADOQuery;)
……
public
procedure Dataconn1(SqlComm:String;OpenOrExe:Boolean) ;
……
{$R *.dfm}
……
Procedure Tform1.Dataconn1(SqlComm:String;openOrExe:Boolean);
begin
Try
ADOQueryfilelist.Close;
ADOQueryfilelist.SQL.Clear;
ADOQueryfilelist.SQL.Add(SqlComm);
if OpenOrExe=True then
ADOQueryfilelist.Open
else
ADOQueryfilelist.ExecSQL; Except
Application.MessageBox('数据库异常','数据库错误',MB_OK);
end;
end;
……
我在form2中有:
……
type
procedure BtnFindClick(Sender: TObject);
……
{$R *.dfm}
……
procedure Tform2.BtnFindClick(Sender: TObject);
var
findcount:integer;
findsql:string;
begin
findsql:='select * from tablename where substring(fieldname,1,2)='01'';
form1.Dataconn1(findsql,true);
findcount:=form1.ADOQueryfilelist.RecordCount;//执行时老是在这句出错,为什么?
Application.MessageBox('共找到findcount条记录','信息提示',MB_OK);//这里“findcount”这个变量可以这样夹在中间吗?
end;
……
end.//上述程序编译顺利通过,但是在执行时老是在 “findcount:=form1.ADOQueryfilelist.RecordCount;”一句出错。这是为什么?高手帮看一下,拜托了
……
public
procedure Dataconn1(SqlComm:String;OpenOrExe:Boolean) ;
……
{$R *.dfm}
……
Procedure Tform1.Dataconn1(SqlComm:String;openOrExe:Boolean);
begin
Try
ADOQueryfilelist.Close;
ADOQueryfilelist.SQL.Clear;
ADOQueryfilelist.SQL.Add(SqlComm);
if OpenOrExe=True then
ADOQueryfilelist.Open
else
ADOQueryfilelist.ExecSQL; Except
Application.MessageBox('数据库异常','数据库错误',MB_OK);
end;
end;
……
我在form2中有:
……
type
procedure BtnFindClick(Sender: TObject);
……
{$R *.dfm}
……
procedure Tform2.BtnFindClick(Sender: TObject);
var
findcount:integer;
findsql:string;
begin
findsql:='select * from tablename where substring(fieldname,1,2)='01'';
form1.Dataconn1(findsql,true);
findcount:=form1.ADOQueryfilelist.RecordCount;//执行时老是在这句出错,为什么?
Application.MessageBox('共找到findcount条记录','信息提示',MB_OK);//这里“findcount”这个变量可以这样夹在中间吗?
end;
……
end.//上述程序编译顺利通过,但是在执行时老是在 “findcount:=form1.ADOQueryfilelist.RecordCount;”一句出错。这是为什么?高手帮看一下,拜托了
解决方案 »
- ORACLE读写BLOB的问题
- 大家给推荐几款数据辅助工具(SQL、Oracle)
- mapx问题,创建一个点图元,线图元
- Rave 中不只如何解决的问题!
- 散分!顺便问及劳动法真能保护我们劳动者权益吗???????????????????????????????
- 如何修改BUTTON控件的属性或事件?
- 急急急!!今天晚上就要打包了。怎么在installshield里定义一个可以让用户选择安装路径的窗口?
- 到底如何才能实现程序的锁定?
- 如何在Win2000下调用Win2000样式的打开对话框?
- 在全局的Var下设置变量,和与在private中设置的有何区别?
- 招聘北京delphi程序员
- Delphi操作DBF的问题?
findsql:='select * from tablename where substring(fieldname,1,2)='01'';
b:=Assigned(Form1);
if b then
showmessage('ok');//看这句执行了么?
form1.Dataconn1(findsql,true);
findcount:=form1.ADOQueryfilelist.RecordCount;//执行时老是在这句出错,为什么?
Application.MessageBox('共找到findcount条记录','信息提示',MB_OK);//这里
FORM1在FORM2中是否有实例被创建?
//下面这句对吗?
findsql:='select * from tablename where substring(fieldname,1,2)='01'';
我认为应该是findsql:='select * from tablename where substring(fieldname,1,2)=''01''';
//这句应该该成:
var str:string;
str:='共找到'+inttostr(findcount)+'条记录';
Application.MessageBox(str,'信息提示',MB_OK);
在前面加一个判断就没问题了。如下
if Not Form1.ADOQueryfilelist.IsEmpty then
FindCount := Form1.ADOQueryfilelist.RecordCount;
2)findsql应该是下面的写法;
findsql:='select * from tablename where substring(fieldname,1,2)=''01''';3)“findcount”这个变量可以这样夹在中间吗?
不行 ,如下
Application.MessageBox(PChar('共找到'+inttostr(findcount)+'条记录'),'信息提示',MB_OK);