查询信息想在dbgrid中显示出来下面代码那错了???????
procedure TForm1.Button2Click(Sender: TObject);
begin
if edit1.Text ='' then
begin
showmessage('请输入要查询的图书号!');
exit;
end;
ado2.Close;
ado2.SQL.Clear;
ado2.SQL.add('select BookID from Book_Info where BookID='''+edit1.Text+'''');
ado2.Open;
if ado2.RecordCount <=0 then
begin
showmessage('该图书号不存在!');
exit;
end;
try
DBGrid1.Refresh;
ado2.Close;
ado2.SQL.Clear;
ado2.SQL.add('Select from Book_Info where BookID='''+edit1.Text+'''');
ado2.open;
DBGrid1.Refresh;
ado2.Close;
ado2.SQL.Clear;
ado2.SQL.add('Select from Book_Info where BookID='''+edit1.Text+'''');
ado2.open;
except
showmessage('查询时出现错误,请核对数据是否正确!');
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
end.
错误提示是SELECT语句问题或标点问题,或者是保留字问题.....
[解决办法]
BookID 是字符型字段吗,需要加引号吗
[解决办法]
如果是int类型的话就不需要那么多引号了 左右去掉2个
[解决办法]
- Delphi(Pascal) code
......try DBGrid1.Refresh; ado2.Close; ado2.SQL.Clear; ado2.SQL.add('Select * from Book_Info where BookID='''+edit1.Text+'''');//原来没字段参数 ado2.open; DBGrid1.Refresh;//为什么要重复下面的语句?// ado2.Close;// ado2.SQL.Clear;// ado2.SQL.add('Select from Book_Info where BookID='''+edit1.Text+'''');// ado2.open;except showmessage('查询时出现错误,请核对数据是否正确!');end;......