DELPHI中的LISTVIEW数据查询
这是下面的程序,运行的时候弹出一个叫database login的对话框,点OK之后,LISTVIEW上没有出现查询的结果,小弟感激不尽
procedure TForm1.Button1Click(Sender: TObject);
var
Content: string;
begin
try
ListView1.Items.Clear;
with form1.ADOQuery1 do
begin
Content:=Edit2.Text;
SQL.Clear;
if RadioButton1.Checked then
begin
SQL.Add('select * from 2009 where 姓名 like :姓名');
Parameters.ParamByName('姓名').value := Content;
end;
if RadioButton2.Checked then
begin
SQL.Add('select * from 2009 where 分厂 like :分厂');
Parameters.ParamByName('分厂').value := Content;
end;
if RadioButton3.Checked then
begin
SQL.Add('select * from 2009 where 寝室号 like :寝室号');
Parameters.ParamByName('寝室号').value := Content;
end;
Open;
while not Eof do
begin
with ListView1.Items.Add do
begin
Caption := FieldByName('姓名').AsString;
SubItems.Add(FieldByName('手机号').AsString);
SubItems.Add(FieldByName('所在分厂').AsString);
SubItems.Add(FieldByName('寝室号').AsString);
SubItems.Add(FieldByName('qq号').AsString);
end;
Next;
end;
StaticText1.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;