下面是我通过LISTVIEW做的一个简单的查询窗口,显示的查询条数正确,说明编译和数据连接都没问题,但是LISTVIEW中却没有数据显示,这是为什么呢,望高手们指点,小弟感激不尽procedure Tform1.Button1Click(Sender: TObject);
var
Content: string;
begin
try
ListView1.Items.Clear; with 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('寝室号').AsString);
SubItems.Add(FieldByName('qq号').AsString); end;
Next;
end; StaticText1.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;procedure TForm1.RadioButton1Click(Sender: TObject);
begin
Edit2.Text := '';
end;end.
var
Content: string;
begin
try
ListView1.Items.Clear; with 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('寝室号').AsString);
SubItems.Add(FieldByName('qq号').AsString); end;
Next;
end; StaticText1.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;procedure TForm1.RadioButton1Click(Sender: TObject);
begin
Edit2.Text := '';
end;end.
解决方案 »
- TrayIcon缺少的简单问题,求助!在线等.谢谢!!!!!!
- 如何实现photoshop里 滤镜 下 塑料包装 的功能?或者有谁知道它的算法?
- ★★★★★★★★写通用查询模块时碰到的两个问题★★★★★★★★★★
- 为什么在连接完中间层正确后,clientDataSet要add all fields时出现"vaiant is not array"
- 怎样把Access的数据批量传送到远方的SQL Server,各位前辈希望提供下思路和代码!
- 主界面设计?
- 判断表存在与否的问题??
- 哪里有Dbchart方面的文章,请介绍一下
- 网络文件传输
- 請問大家: 工具欄圖標哪有?
- 如何在数据库里面增减的问题?
- Delphi 中ADOQUERY 三级字表的批量提交问题
先改成不用参数的
SQL.Add('select * from 2009 where 姓名 like ''%王%'' ');
var
Content: string;
begin ListView1.Items.Clear; with ADOQuery1 do
begin
Content:=Edit2.Text;
SQL.Close;
SQL.Clear;
if RadioButton1.Checked then
begin
SQL.Add('select * from 2009 where 姓名 like :A');
Parameters.ParamByName('A').value := Content+'%';
end
else
if RadioButton2.Checked then
begin
SQL.Add('select * from 2009 where 所在分厂 like :A');
Parameters.ParamByName('A').value := '%'+Content+'%';
end
else
if RadioButton3.Checked then
begin
SQL.Add('select * from 2009 where 寝室号=:A');
Parameters.ParamByName('A').value := Content;
end; try
open ;
except
MessageDlg('查询失败',mtError,[mbok],0);
end; 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('寝室号').AsString);
SubItems.Add(FieldByName('qq号').AsString); end;
Next;
end; StaticText1.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;end;SQL语句,若用了like,而未用到通配符%,和=号相同效果,如查"寝室号"这句,直接用=号,效率会更高
like和%搭配使用,可以在前,后或前后加上%,看你要的结果了