关于select语句的简单问题
发现如果select语句没有找到任何记录,那么若要执行下个语句,比如close时候,就会出错!
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, Db, ADODB, StdCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
procedure Button1Click(Sender: TObject);
procedure ADOQAfterOpen(DataSet: TDataSet);
private
{ Private declarations }
public
sqlstring:string;
procedure ExeSQL(SQLString:string);{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ExeSQL(SQLString:string);
var sqlstr:string;
begin
sqlstr:=SQLString;
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add(sqlstr);
try
Open;
except
ShowMessage('Open database failed');
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
Index:string;
begin
for i:=1 to 99 do
begin
showmessage(inttostr(i));
Index:=inttostr(i);
SqlString:='SELECT * FROM list WHERE indexsss='+''''+Index+'''';
Exesql(sqlstring);
end;
end;
end.
当i=1时,程序正常,i=2时,执行到adoquery1.close就出错了!提示Either BOF or EOF is true, or the current record has been deleted.....