如何我把listbox中的每条记录 在我创建的sql数据库中查找到 并输出sql中的和这条记录相关的其他字段到另一个listbox中
你们好啊!我再请教你一个问题啊
就是 如何我把listbox中的每条记录 在我创建的sql数据库中查找到 并输出sql中的和这条记录相关的其他字段到另一个listbox中
问题点数:0、回复次数:17Top
1 楼ihihonline(潇潇->戒烟)回复于 2003-06-02 09:04:57 得分 0
Procedure ...
var
vIndex Integer;
begin
for vIndex := 0 to ListBox1.Items.Count - 1 do
with TempQuery do
begin
if Active then
Active := False;
Parameters(0).Value := ListBox1.Items[vIndex].Text;
Prepared;
Open;
ListBox2.Add(....)
end;
end;
----------------
沉沦中..........
Top
2 楼ihihonline(潇潇->戒烟)回复于 2003-06-02 09:06:34 得分 0
Procedure ...
var
vIndex Integer;
begin
TempQuery.Close;
TempQuery.SQL.Add('Select FieldName From TableName where CantFieldName = :Value');
for vIndex := 0 to ListBox1.Items.Count - 1 do
with TempQuery do
begin
if Active then
Active := False;
Parameters(0).Value := ListBox1.Items[vIndex].Text;
Prepared;
Open;
ListBox2.Add(....)
end;
end;
----------------
沉沦中..........
Top
3 楼machael724(路客)回复于 2003-06-02 10:44:13 得分 0
输出和它相关的数据库中其他域 zhzhmc,zhzhqc的记录到listbox2中去
如何编码 listbox.add(...) 再具体一些
Top
4 楼tomboy0(小波波)回复于 2003-06-02 11:57:14 得分 0
......
open;
ListBox2.clear;
ListBox3.clear;
first
for i:=0 to recordcount-1 do
begin
ListBox2.items.add(fieldbyname('zhzhmc').asstring);
ListBox3.items.add(fieldbyname('zhzhqc').asstring);
next;
end;
Top
5 楼machael724(路客)回复于 2003-06-02 15:39:54 得分 0
还是有问题啊
listbox2 里统计出来的并不是和listbox里的记录在数据库和它相关的字段啊
统计出来的不匹配啊
Top
6 楼ihihonline(潇潇->戒烟)回复于 2003-06-02 17:42:53 得分 0
Procedure ...
var
vIndex Integer;
begin
TempQuery.Close;
TempQuery.SQL.Add('Select FieldName From TableName where CantFieldName = :Value');
for vIndex := 0 to ListBox1.Items.Count - 1 do
with TempQuery do
begin
if Active then
Active := False;
Parameters(0).Value := ListBox1.Items[vIndex].Text;
Prepared;
Open;
While Not Eof do
begin
ListBox2.Items.Add(Fieldbyname('zhzhmc').AsString);
ListBox2.items.add(fieldbyname('zhzhqc').asstring);
Next;
end;
end;
end;Top
7 楼lovelymelon(小人物)回复于 2003-06-02 17:56:54 得分 0
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,i1,j1:integer;
s:string;
begin
form1.ListBox2.Items.Clear;
i:=form1.ListBox1.Items.Count;
if i>0 then
begin
for j:= 0 to i-1 do
begin
s:=form1.ListBox1.Items.Strings[j];
form1.ADOQuery1.Close;
form1.ADOQuery1.SQL.Add('select * from zhuangzhuang1 where zhzhmc=:s1');
form1.ADOQuery1.Parameters.ParamByName('s1').Value:=s;
form1.ADOQuery1.Open;
i1:=form1.ADOQuery1.RecordCount;
if i1=1 then
begin
form1.ListBox2.Items.Add(form1.ADOQuery1.FieldValues['zhzhbh']);
form1.ListBox2.Items.Add(form1.ADOQuery1.FieldValues['zhzhqz']);
end;
end;
end;
end;Top
8 楼machael724(路客)回复于 2003-06-02 19:06:36 得分 0
不行啊我按照ihihonline(小小->沉沦中..........) 的方法怎么在 listbox2中全把数据库中的东西给导出来而不是受限制于listbox1中的记录呢
我按照lovelymelon(小人物) 的方法试,可是在listbox2中什么东西都导不出来啊Top
9 楼lovelymelon(小人物)回复于 2003-06-02 19:27:27 得分 0
可能是查询出的数据不只一条,改成这样试试
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,i1,j1:integer;
s:string;
begin
form1.ListBox2.Items.Clear;
i:=form1.ListBox1.Items.Count;
if i>0 then
begin
for j:= 0 to i-1 do
begin
s:=form1.ListBox1.Items.Strings[j];
form1.ADOQuery1.Close;
form1.ADOQuery1.SQL.Add('select * from zhuangzhuang1 where zhzhmc=:s1');
form1.ADOQuery1.Parameters.ParamByName('s1').Value:=s;
form1.ADOQuery1.Open;
i1:=form1.ADOQuery1.RecordCount;
if i1>0 then
begin
for j1:= 0 to i1-1 do
begin
form1.ListBox2.Items.Add(form1.ADOQuery1.FieldValues['zhzhbh']);
form1.ListBox2.Items.Add(form1.ADOQuery1.FieldValues['zhzhqz']);
form1.ADOQuery1.Next;
end;
end;
end;
end;
end;Top
10 楼ihihonline(潇潇->戒烟)回复于 2003-06-02 19:30:01 得分 0
Procedure ...
var
vIndex Integer;
begin
TempQuery.Close;
TempQuery.SQL.Add('Select FieldName From TableName where CantFieldName = :Value');
with TempQuery do
begin
if Active then
Active := False;
Parameters(0).Value := ListBox1.Items[vIndex].Text;
Prepared;
Open;
While Not Eof do
begin
ListBox2.Items.Add(Fieldbyname('zhzhmc').AsString);
ListBox2.items.add(fieldbyname('zhzhqc').asstring);
Next;
end;
end;
end;
Top
11 楼lovelymelon(小人物)回复于 2003-06-02 19:57:59 得分 0
procedure TForm1.ListBox1Click(Sender: TObject);
var
i,j,i1,j1:integer;
s:string;
begin
form1.ListBox2.Items.Clear;
i:=form1.ListBox1.Items.Count;
if i>0 then
begin
for j:=0 to i-1 do
begin
if form1.ListBox1.Selected[j] then
s:=form1.ListBox1.Items.Strings[j];
end;
end;
form1.ADOQuery1.Close;
form1.ADOQuery1.SQL.Add('select * from zhuangzhuang1 where zhzhmc=:s1');
form1.ADOQuery1.Parameters.ParamByName('s1').Value:=s;
form1.ADOQuery1.Open;
i1:=form1.ADOQuery1.RecordCount;
if i1>0 then
begin
for j1:= 0 to i1-1 do
begin
form1.ListBox2.Items.Add(form1.ADOQuery1.FieldValues['zhzhbh']);
form1.ListBox2.Items.Add(form1.ADOQuery1.FieldValues['zhzhqz']);
form1.ADOQuery1.Next;
end;
end;
end;Top
12 楼henry2003(阿波)回复于 2003-06-02 20:05:25 得分 0
var i,j:integer;
Item:array of String;
begin
j:=0;
SetLength(Item,ListBox1.Items.Count);
for i :=1 to ListBox1.Items.Count-1 do
if Query1.Locate('xx',ListBox1.Items[i],[]) then
Begin
Item[j]:=Query1.FieldValues['xx'];
Inc(J);
end;
for i:=0 to High(Item) do
if Item[i]<>'' then
ListBox1.Items.Add(Item[i])
end;
Top
13 楼bbs791109(小别)回复于 2003-06-02 20:20:11 得分 0
var
i Integer;
begin
for i := 0 to ListBox1.Items.Count - 1 do
with Query1 do
begin
if Active then
Active := False;
Parameters(0).Value := ListBox1.Items[i].Text;
Prepared;
Open;
while not eof do
begin
ListBox2.items.Add(fieldbyname('').asstring);
next;
end;
close;
end;
end;Top
14 楼jpyc(九品-沉默)回复于 2003-06-02 21:53:03 得分 0
做了个离子,给个邮箱,跟你发过去Top
15 楼things(Loving You)回复于 2003-06-02 21:55:05 得分 0
upTop
16 楼xiaoyuer0851(红旗下的蛋)回复于 2003-06-03 08:48:47 得分 0
楼主,好的
我解决了,马上给你回帖子
谢谢!~~~Top
17 楼blueshrimp(下着沙-软件民工)回复于 2003-06-03 09:34:16 得分 0
楼主够幸福的了Top




