数据库结构如下:
省:id,name
市:sid,sname,id
县:xid,xname,sid,id

解决方案 »

  1.   

    其实你可以只建你的那最后一张表,用Tree型结构来显示数据,如果非用ComboBox,也只要最后那一张表就可以了,用带条件的SQL语句取出数据就是
      

  2.   

    在省份combobox的Onchange属性中,填写代码,根据所选择的省份,更新市、县就可以了阿
      

  3.   

    回答 yanyuwuhen(颜羽)我知道它的实现原理~问题是如何来写代码~~55555555555555555555555555
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, ADODB;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        ComboBox2: TComboBox;
        ComboBox3: TComboBox;
        ADOQuery1: TADOQuery;
        procedure FormCreate(Sender: TObject);
        procedure ComboBox1Change(Sender: TObject);
        procedure ComboBox2Change(Sender: TObject);
      private
        StringList1, StringList2, StringList3 : TStringList;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      StringList1 := TStringList.Create;
      StringList2 := TStringList.Create;
      StringList3 := TStringList.Create;
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Select * from 省 ');
        Open;
        while not Eof do
        begin
          ComboBox1.Items.Add(FieldByName('name').AsString);
          StringList1.Add(FieldByName('ID').AsString);
          Next;
        end;  end;
    end;procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
      StringList2.Clear;
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Select * from 市 where id=' + StringList1.Strings[ComboBox1.ItemIndex]);
        Open;
        while not Eof do
        begin
          ComboBox2.Items.Add(FieldByName('sname').AsString);
          StringList2.Add(FieldByName('SID').AsString);
          Next;
        end;
      end;
    end;procedure TForm1.ComboBox2Change(Sender: TObject);
    begin
      StringList3.Clear;
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Select * from 县 where sid=' + StringList2.Strings[ComboBox2.ItemIndex]);
        Open;
        while not Eof do
        begin
          ComboBox3.Items.Add(FieldByName('xname').AsString);
          StringList3.Add(FieldByName('XID').AsString);
          Next;
        end;
      end;end;end.
      

  5.   

    100分到手了,我给你写个省的,市、县类似
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      pCodeInfoSheng=^TCodeInfoSheng;
      TCodeInfoSheng =Record
        ID : integer;
        Name : String;
      end;       //  省
                   
      pCodeInfoShI=^TCodeInfoShI;
      TCodeInfoShI =Record
        ID : integer;
        sid : integer;
        SName : String;  end;    // 市  pCodeInfoXian=^TCodeInfoXian;
      TCodeInfoXian =Record
        xid : integer;
        sid : integer;
        ID : integer;
        Name : String;
      end;   //  县  TForm1 = class(TForm)
        Combox_sheng: TComboBox;
        btm_sheng: TButton;
        ComBox_Shi: TComboBox;
        ComBox_xian: TComboBox;
        Button1: TButton;
        procedure btm_shengClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btm_shengClick(Sender: TObject);
    var
      sheng : pCodeInfoSheng;     //加载省
    begin
      New(Sheng);
      sheng.ID:=100;
      Sheng.Name:='北京';
      Combox_sheng.Items.AddObject(sheng.Name,TObject(sheng));end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Combox_sheng.Clear;
    end;procedure TForm1.Button1Click(Sender: TObject);
    Var
      I : integer;
    begin
      //读取信息
      I:= Combox_sheng.ItemIndex;
      if I>=0 then
      Showmessage(pCodeInfoSheng(Combox_sheng.Items.Objects[i]).Name);end;end.
      

  6.   

    这样不管你的字段有多少个,都可以存放,不要建很多的StringList了,很麻烦,不好维护