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语句问题或标点问题,或者是保留字问题.....
是不是IntToString的问题?
如果是的话应该怎么写??
求解!!
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语句问题或标点问题,或者是保留字问题.....
是不是IntToString的问题?
如果是的话应该怎么写??
求解!!
改成select * 看看
另外如果id是数字类型的话不加引号
select * from
begin
try
if edit1.Text ='' then
begin
showmessage('请输入要查询的图书号!');
exit;
end;
ado2.Close;
ado2.SQL.Clear;
ado2.SQL.add('select * from Book_Infowhere BookID='''+edit1.Text+'''');
ado2.Open;
if ado2.RecordCount <=0 then
begin
showmessage('该图书号不存在!');
exit;
end;
except
showmessage('查询时出现错误,请核对数据是否正确!');
end;
end;话说你,中间了那两个查询有什么用,DBGrid1.Refresh;不需要吧,当你ado2.Open;了时候,数据已经查询打开了,DBGrid1里面没有数据,要吗是你DBGrid1里面的没有关联数据源DataSource1
改为
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+'''');-->Select * From ....