最近在做一个关于listbox的查询,遇到了一些问题。
就是把要查询listbox里面的所有值做查询条件,点查询按钮将值输出到TDBGRID里面?????请问如何做呢?
就是把要查询listbox里面的所有值做查询条件,点查询按钮将值输出到TDBGRID里面?????请问如何做呢?
解决方案 »
- 使用二进制流技术导出Excel文件的版本太低问题
- 这样的表内容如何写SQL语句,在线等,狂谢
- 谁有PUDN的帐号,帮我下个东西~~
- 客户的安装上程序,数据库引擎的版本太低,Borland Database Engine (error $3E06)
- 关于图形拖放
- 最后的散份贴 (3)
- 一幅BMP图,如何将白色底色透明?
- 救救我吧!如何知道Delta中每一条记录的状态(在线等待)
- ☆☆高分求助☆☆在程序中怎样调用另一个程序?又怎么样知道那个程序运行结束了??
- 在Delphi里 DragAcceptFiles,DragQueryFile,DragFinish如何正确使用?
- 高分查错!TMemoryStream对象赋给TStream对象出错!
- 实现顺序播放两个avi文件,用一个线程判断播放器播放完一个,再播另一个
begin
GetValue:= ListBox1.Items.Strings[i];
{以GetValue为条件查询..执行插入到TDBGrid相关操作..}
end
procedure TForm1.Button3Click(Sender: TObject);
var
str,s:string;
i:integer;
begin s :='select * from A where aname in';{查表中aname这个字段}
for i :=0 to ListBox1.Items.Count-1 do
if str='' then
str:=str+''''+ListBox1.Items.Strings[i]+''''
else
str:=str+','''+ListBox1.Items.Strings[i]+'''';
str:=s+'('+str+')'; with adoquery1 do begin
close;
sql.Text:=str;
open;
end;
end;
begin
GetValue:= ListBox1.Items.Strings[i];
{以GetValue为条件查询..执行插入到TDBGrid相关操作..}
end
这步会做,关键就这样循环如何执行SQL查询?请能否具体点好吗??谢谢!!
with dataa.ADOQuery2 do
begin
close;
sql.Clear;
for i:=0 to listbox1.Count-1 do
begin
sql.Add('select * from 收入明细表 where shouruxiangmu=:a');
Parameters.ParamByName('a').Value :=listbox1.Items[i];
open;end;
if dataa.ADOQuery2.RecordCount>0 then
DataSource1.DataSet := Dataa.ADOQuery2;
end;
for i :=0 to ListBox1.Items.Count-1 do
if str='' then
str:=str+''''+ListBox1.Items.Strings[i]+''''
else
str:=str+','''+ListBox1.Items.Strings[i]+'''';
str:=s+'('+str+')';这不是拼查询语句吗?
for i:= 0 to ListBox1.Items.Count -1 do
begin
ADOQuery1.Sql.text:= 'insert into #TEMPshouruxiangmu values('''+
ListBox1.Items.Strings[i]+'''';
ADOQuery1.excsql;
end最后 select * from 收入明细表 where shouruxiangmu in (select * from #TEMPshouruxiangmu )
一次返回所有的,这不就行了?或许会用重复,你就加上DISTINCT
var
str,s:string;
i:integer;
begin s :='select * from 收入明细表 where shouruxiangmu in ';
for i :=0 to ListBox1.Items.Count-1 do
if str='' then
str:=str+''''+ListBox1.Items.Strings[i]+''''
else
str:=str+','''+ListBox1.Items.Strings[i]+'''';
str:=s+'('+str+')'; with adoquery1 do begin
close;
sql.Text:=str;
open;
end;
procedure TForm10.SpeedButton5Click(Sender: TObject);
var
str,s:string;
i:integer;
begin
if radiogroup1.ItemIndex=0 then
begin
s :='select * from 收入明细表 where shouruxiangmu in';{查表中aname这个字段}
for i :=0 to ListBox2.Items.Count-1 do
if str='' then
str:=str+''''+ListBox2.Items.Strings[i]+''''
else
str:=str+','''+ListBox2.Items.Strings[i]+'''';
str:=s+'('+str+')'; with dataa.ADOQuery2 do begin
close;
sql.Text:=str;
open;
end;
if dataa.ADOQuery2.RecordCount>0 then
DataSource1.DataSet := Dataa.ADOQuery2;
end
else
begin
s :='select * from 支出明细表 where zhichuxiangmu in';
for i :=0 to ListBox2.Items.Count-1 do
if str='' then
str:=str+''''+ListBox2.Items.Strings[i]+''''
else
str:=str+','''+ListBox2.Items.Strings[i]+'''';
str:=s+'('+str+')'; with dataa.ADOQuery2 do begin
close;
sql.Text:=str;
open;
end;
if dataa.ADOQuery2.RecordCount>0 then
DataSource1.DataSet := Dataa.ADOQuery2;
end;
end;
IT民工 谢谢你!!