Project project1.exe raised exception class EDatabaseError with message ‘query1: no sql statement available’.process stopped.use step or run to continue.我是个新手,请高手帮帮忙吧··
Query1.SQL.Add('select * from flight where FlightNo=:s0 and StrDate=:StrDate'); Query1.ParamByName('s0').AsString :=Edit1.Text ; Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text ); Query1.Open ; if query1.RecNo =0 then begin application.MessageBox('此航班不存在!','提示信息',mb_ok) end else begin Query1.RequestLive :=true; DBgrid1.Fields[0].DisplayLabel :='航班号'; DBgrid1.Fields[1].DisplayLabel :='起飞日期'; DBgrid1.Fields[2].DisplayLabel :='起飞时间'; DBgrid1.Fields[3].DisplayLabel :='起飞城市'; DBgrid1.Fields[4].DisplayLabel :='到达日期'; DBgrid1.Fields[5].DisplayLabel :='到达时间'; DBgrid1.Fields[6].DisplayLabel :='到达城市'; end; end;
上面就是这部分的代码,大家帮忙看哈,有没有可能是在DATABASE里面创建的数据库文件有问题啊
with query1 do begin query1.Close; query1.SQL.Clear; Query1.SQL.Add('select * from flight where FlightNo=:s0 and StrDate=:StrDate'); Query1.ParamByName('s0').AsString :=Edit1.Text ; Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text ); Query1.Open ; end; ...
单步调试时错误提示 datasource1:circular datalinks are not allowed
project project1.exe raised exception class EDBEngineError with message 'invalid use of keyword Token:order Line number:1'process stopped.use step or run to continue. 这又是怎么回事啊,郁闷了!!
数据库是什么,database联接数据库正常吗 还有没有其它的代码“'invalid use of keyword ”这提示的是关键字错误 Query1.ParamByName('s0').AsString :=Edit1.Text ; Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text ); 改成 Query1.ParamByName('s0').value:=Edit1.Text ; Query1.ParamByName('StrDate').value:=strtodate(edit2.Text ); 试试
unit flightquery;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;type TFliQuery = class(TForm) Label1: TLabel; Label2: TLabel; Edit1: TEdit; Edit2: TEdit; DataSource1: TDataSource; Query1: TQuery; DBGrid1: TDBGrid; ButtonYes: TButton; ButtonExit: TButton; procedure ButtonExitClick(Sender: TObject); procedure ButtonYesClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var FliQuery: TFliQuery;implementation{$R *.dfm}procedure TFliQuery.ButtonExitClick(Sender: TObject); begin Query1.Close; end;procedure TFliQuery.ButtonYesClick(Sender: TObject); begin DBgrid1.DataSource :=datasource1; DBgrid1.ReadOnly :=true; datasource1.DataSet :=Query1; Query1.SQL.Clear ; //先查询数据库,看看所指定的航班存不存在 Query1.SQL.Add('select * from flight where FlightNo=:s0 and StrDate=:StrDate'); Query1.ParamByName('s0').AsString :=Edit1.Text ; Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text ); Query1.Open ; if query1.RecNo =0 then begin application.MessageBox('此航班不存在!','提示信息',mb_ok) end else begin Query1.RequestLive :=true; DBgrid1.Fields[0].DisplayLabel :='航班号'; DBgrid1.Fields[1].DisplayLabel :='起飞日期'; DBgrid1.Fields[2].DisplayLabel :='起飞时间'; DBgrid1.Fields[3].DisplayLabel :='起飞城市'; DBgrid1.Fields[4].DisplayLabel :='到达日期'; DBgrid1.Fields[5].DisplayLabel :='到达时间'; DBgrid1.Fields[6].DisplayLabel :='到达城市'; end; end;//初始化工作,设定默认值 procedure TFliQuery.FormCreate(Sender: TObject); begin edit1.Text :='fly'; edit2.Text :='2009-09-09'; end;end.这是航班查询模块的全部代码,其他模块的跟这差不多,不知道哪里错了,麻烦高手看下啊
你把AsString和AsDateTime改成Value 如果还不行,你直接写SQL语句吧,不要用Param 比如 query1.sql.add(format('select * from flight where flightno=''%s''',[Edit1.text])); 单引号不行改双引号另,最好先做query1.close;
procedure TFliQuery.ButtonYesClick(Sender: TObject); begin DBgrid1.DataSource :=datasource1; DBgrid1.ReadOnly :=true; datasource1.DataSet :=Query1; Query1.Close; //++++++++++++++++++++++++++ Query1.SQL.Clear ; //先查询数据库,看看所指定的航班存不存在 Query1.SQL.Add('select * from flight where FlightNo=:s0 and StrDate=:StrDate'); Query1.Parameters.ParamByName('s0').Value:=Edit1.Text ; Query1.Parameters.ParamByName('StrDate').Value:=strtodate(edit2.Text ); Query1.Open ; if query1.RecNo =0 then begin application.MessageBox('此航班不存在!','提示信息',mb_ok) end else begin Query1.RequestLive :=true; DBgrid1.Fields[0].DisplayLabel :='航班号'; DBgrid1.Fields[1].DisplayLabel :='起飞日期'; DBgrid1.Fields[2].DisplayLabel :='起飞时间'; DBgrid1.Fields[3].DisplayLabel :='起飞城市'; DBgrid1.Fields[4].DisplayLabel :='到达日期'; DBgrid1.Fields[5].DisplayLabel :='到达时间'; DBgrid1.Fields[6].DisplayLabel :='到达城市'; end; end; 這樣試試?
Query1.ParamByName('s0').AsString :=Edit1.Text ;
Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text );
Query1.Open ;
if query1.RecNo =0 then
begin
application.MessageBox('此航班不存在!','提示信息',mb_ok)
end
else begin
Query1.RequestLive :=true;
DBgrid1.Fields[0].DisplayLabel :='航班号';
DBgrid1.Fields[1].DisplayLabel :='起飞日期';
DBgrid1.Fields[2].DisplayLabel :='起飞时间';
DBgrid1.Fields[3].DisplayLabel :='起飞城市';
DBgrid1.Fields[4].DisplayLabel :='到达日期';
DBgrid1.Fields[5].DisplayLabel :='到达时间';
DBgrid1.Fields[6].DisplayLabel :='到达城市';
end;
end;
begin
query1.Close;
query1.SQL.Clear;
Query1.SQL.Add('select * from flight where FlightNo=:s0 and StrDate=:StrDate');
Query1.ParamByName('s0').AsString :=Edit1.Text ;
Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text );
Query1.Open ;
end;
...
Token:order
Line number:1'process stopped.use step or run to continue.
这又是怎么回事啊,郁闷了!!
还有没有其它的代码“'invalid use of keyword ”这提示的是关键字错误
Query1.ParamByName('s0').AsString :=Edit1.Text ;
Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text );
改成
Query1.ParamByName('s0').value:=Edit1.Text ;
Query1.ParamByName('StrDate').value:=strtodate(edit2.Text );
试试
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;type
TFliQuery = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
DataSource1: TDataSource;
Query1: TQuery;
DBGrid1: TDBGrid;
ButtonYes: TButton;
ButtonExit: TButton;
procedure ButtonExitClick(Sender: TObject);
procedure ButtonYesClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
FliQuery: TFliQuery;implementation{$R *.dfm}procedure TFliQuery.ButtonExitClick(Sender: TObject);
begin
Query1.Close;
end;procedure TFliQuery.ButtonYesClick(Sender: TObject);
begin
DBgrid1.DataSource :=datasource1;
DBgrid1.ReadOnly :=true;
datasource1.DataSet :=Query1;
Query1.SQL.Clear ;
//先查询数据库,看看所指定的航班存不存在
Query1.SQL.Add('select * from flight where FlightNo=:s0 and StrDate=:StrDate');
Query1.ParamByName('s0').AsString :=Edit1.Text ;
Query1.ParamByName('StrDate').AsDateTime :=strtodate(edit2.Text );
Query1.Open ;
if query1.RecNo =0 then
begin
application.MessageBox('此航班不存在!','提示信息',mb_ok)
end
else begin
Query1.RequestLive :=true;
DBgrid1.Fields[0].DisplayLabel :='航班号';
DBgrid1.Fields[1].DisplayLabel :='起飞日期';
DBgrid1.Fields[2].DisplayLabel :='起飞时间';
DBgrid1.Fields[3].DisplayLabel :='起飞城市';
DBgrid1.Fields[4].DisplayLabel :='到达日期';
DBgrid1.Fields[5].DisplayLabel :='到达时间';
DBgrid1.Fields[6].DisplayLabel :='到达城市';
end;
end;//初始化工作,设定默认值
procedure TFliQuery.FormCreate(Sender: TObject);
begin
edit1.Text :='fly';
edit2.Text :='2009-09-09';
end;end.这是航班查询模块的全部代码,其他模块的跟这差不多,不知道哪里错了,麻烦高手看下啊
如果还不行,你直接写SQL语句吧,不要用Param
比如
query1.sql.add(format('select * from flight where flightno=''%s''',[Edit1.text]));
单引号不行改双引号另,最好先做query1.close;
begin
DBgrid1.DataSource :=datasource1;
DBgrid1.ReadOnly :=true;
datasource1.DataSet :=Query1;
Query1.Close; //++++++++++++++++++++++++++
Query1.SQL.Clear ;
//先查询数据库,看看所指定的航班存不存在
Query1.SQL.Add('select * from flight where FlightNo=:s0 and StrDate=:StrDate');
Query1.Parameters.ParamByName('s0').Value:=Edit1.Text ;
Query1.Parameters.ParamByName('StrDate').Value:=strtodate(edit2.Text );
Query1.Open ;
if query1.RecNo =0 then
begin
application.MessageBox('此航班不存在!','提示信息',mb_ok)
end
else begin
Query1.RequestLive :=true;
DBgrid1.Fields[0].DisplayLabel :='航班号';
DBgrid1.Fields[1].DisplayLabel :='起飞日期';
DBgrid1.Fields[2].DisplayLabel :='起飞时间';
DBgrid1.Fields[3].DisplayLabel :='起飞城市';
DBgrid1.Fields[4].DisplayLabel :='到达日期';
DBgrid1.Fields[5].DisplayLabel :='到达时间';
DBgrid1.Fields[6].DisplayLabel :='到达城市';
end;
end;
這樣試試?