CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

如何我把listbox中的每条记录 在我创建的sql数据库中查找到 并输出sql中的和这条记录相关的其他字段到另一个listbox中

楼主machael724(路客)2003-06-01 19:35:50 在 Delphi / VCL组件开发及应用 提问

 
  你们好啊!我再请教你一个问题啊  
  就是   如何我把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

相关问题

  • 如何获得SQL数据库中备注字段的内容?
  • SQL数据库表中ID字段怎样自动排序
  • SQL数据库里的图像字段绑定问题
  • SQL数据库中设计表字段名用中文可好?
  • 关于SQL数据库字段类型问题
  • 删除字段(SQL数据库)的问题
  • 求教SQL数据库的Image类型的字段的操作。
  • 插入sql数据库ntext字段的错误,指点
  • SQL数据库字段类型的问题!
  • SQL数据库字段类型的问题!

关键词

  • active
  • sql
  • listbox
  • vindex
  • 记录
  • tempquery
  • begin
  • items
  • open
  • add

得分解答快速导航

  • 帖主:machael724

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo