我用一个listbox显示一个库中的表的名称,我想一点击这个表的名称在另外的listbox或者combobox中显示出这表中所有的数据段的名称

解决方案 »

  1.   

    得到表明可以去查询数据库的系统表 或是通过 connection得到
    con1: TADOConnection;
       mmo1: TMemo;
     con1.GetTableNames(mmo1.Lines,False); 
      

  2.   

    表中所有的数据段的名称
    con1: TADOConnection;
       mmo2: TMemo; 
    con1.GetFieldNames(TableName,mmo2.Lines);
      

  3.   

    ListBox1显示数据表名称,ListBox2显示ListBox1中选择的数据表中所有字段名称:procedure TForm1.Button1Click(Sender: TObject);
    begin
    ListBox1.Items.Clear;
    with adoquery1  do
     begin
      close;
      sql.Text:='SELECT  [name] from sysobjects  where xtype=''U'' order by [name]';
      open;
      while not eof do
        begin
          ListBox1.Items.Add(Fields[0].AsString);
          Next;
         end;
      end;
    end;procedure TForm1.ListBox1Click(Sender: TObject);
    begin
    ListBox2.Items.Clear;
    with adoquery1  do
     begin
      close;
      sql.Text:='select  syscolumns.[name] from syscolumns, sysobjects where sysobjects.id=syscolumns.id  and  sysobjects.[name]='''+ListBox1.Items[ListBox1.ItemIndex]+'''';
      open;
      while not eof do
        begin
          ListBox2.Items.Add(Fields[0].AsString);
          Next;
         end;
      end;
    end;