终极一家 杨过小龙女:关于DELPHI对数据库查询的问题

来源:百度文库 编辑:高考问答 时间:2024/04/29 10:25:51
我想做一个图书管理系统,有一个表单里想做一个对图书的查询,我在查询按钮(BITBTN1)的CLICK事件输入的是以下代码,但是每次点击按钮只能出来第一条记录.这是怎么回事.
RadioButton1的CAPTION是'按ID查询'
RadioButton2的CAPTION是'按书名查询'
RadioButton3的CAPTION是'按作者查询'
RadioButton4的CAPTION是'按出版社查询'
RadioButton5的CAPTION是'按分类查询'
CheckBox1的CAPTION是模糊查询
edit1是用来输入关键字的
listview1是用来显示被搜到的图书的

procedure TForm1.BitBtn1Click(Sender: TObject);
var
Content : string;
begin
try
ListView1.Items.Clear;

with ADOQuery1 do
begin
Content:=Edit1.Text;
if CheckBox1.Checked then
Content := '%'+Content +'%';

SQL.Clear;
if RadioButton1.Checked then
begin
SQL.Add('select * from Book where id like :id');
Parameters.ParamByName('id').value := Content;
end;
if RadioButton2.Checked then
begin
SQL.Add('select * from Book where shuming like :shuming');
Parameters.ParamByName('shuming').value := Content;
end;
if RadioButton3.Checked then
begin
SQL.Add('select * from Book where zuozhe like :zuozhe');
Parameters.ParamByName('zuozhe').value := Content;
end;
if RadioButton4.Checked then
begin
SQL.Add('select * from Book where chubanshe like :chubanshe');
Parameters.ParamByName('chubanshe').value := Content;
end;
if RadioButton5.Checked then
begin
SQL.Add('select * from Book where fenlei like :fenlei');
Parameters.ParamByName('fenlei').value := Content;
end;

Open;

while not Eof do
begin
with ListView1.Items.Add do
begin
Caption := FieldByName('id').AsString;
SubItems.Add(FieldByName('shuming').AsString);
SubItems.Add(FieldByName('zuozhe').AsString);
SubItems.Add(FieldByName('chubanshe').AsString);
SubItems.Add(FieldByName('chubanshijian').AsString);
SubItems.Add(FieldByName('dingjia').AsString);
SubItems.Add(FieldByName('fenlei').AsString);
SubItems.Add(FieldByName('shifoujiechu').AsString);
end;
Next;
end;
StaticText2.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;

end;

小弟不甚感谢啊