假设有个access数据库:e:\test.mdb该数据库里有 n 个table:table1,.....,tablen做个界面,界面显示时,加载上述数据库加载成功后,用combobox显示n个table想查看哪个 table,可以从下列列表中选择想应的表如何实现,谢谢

解决方案 »

  1.   

    最簡單的思路與方法:(供參考之)...
    1.新增一個FORM,拖放一個CXCOMBOBOX,cxgrid,TADOConnection,TADOQuery,TDataSource控件,配置並連接好ACCESS數據庫TEST.mdb;
    2.在form的CREATE或SHOW的事件中寫代碼,用WHILE循環將表名取出賦值給CXCOMBOBOX,再用CASE OF的方法把表名changed後再查詢open相應的表名(即打開相應的數據表)即可...
    3.LZ可參照上面的方法自己動手試試看,如果實現不了;發郵件過來,我抽時間寫個DEMO給你...
      

  2.   

    对于ADOConnection,有一个方法,可以获得表的列表ADOConnection1.GetTableNames(ComboBox1.Items);剩下的就是ComboBox1变化时,根据其内容去select了
    procedure TfrmMain.ComboBox1Change(Sender: TObject);
    begin
      ADOQuery1.Close;
      ADOQuery1.SQL.Text := 'select * from '+ComboBox1.Text;
      ADOQuery1.Open;
    end;
      

  3.   

    UP 查找全部数据、然后在combobox显示出来。
      

  4.   

    procedure TmainForm.cb_stand_idChange(Sender: TObject);
    begin
      with dm.QryPub do
      begin
        close;
        sql.Clear;
        sql.Add('select stand_name from stand where stand_id='''+trim(cb_stand_id.Text)+'''');
        open;
        if not isempty then
        begin
          edt_stand_name.Text:=fieldbyname('stand_name').AsString;
        end
        else
        edt_stand_name.Text:='';
      end;
    end;
      

  5.   

         int tablenum,n;
         String tname,ta,tyear,tmonth,tm;
         TStringList* fList=new TStringList;
         UserMod->Plocal->GetTableNames(fList,false);//Plocal-是数据库连接控件,可以是ADOCONNECTION,DATABASE控件
         for(tablenum=0;tablenum<fList->Count;tablenum++)
         {
          tname=fList->Strings[tablenum];
          ta=tname.SubString(1,1);
          if(ta=='V')
          {
             tyear=tname.SubString(5,4);
             n=StrToInt(tyear)-2003;
             tmonth=tname.SubString(9,2);
             if(StrToInt(tmonth)==1)
               tm="一月";
             if(StrToInt(tmonth)==2)
               tm="二月";
             if(StrToInt(tmonth)==3)
               tm="三月";
             if(StrToInt(tmonth)==4)
               tm="四月";
             if(StrToInt(tmonth)==5)
               tm="五月";
             if(StrToInt(tmonth)==6)
               tm="六月";
             if(StrToInt(tmonth)==7)
               tm="七月";
             if(StrToInt(tmonth)==8)
               tm="八月";
             if(StrToInt(tmonth)==9)
               tm="九月";
             if(StrToInt(tmonth)==10)
               tm="十月";
             if(StrToInt(tmonth)==11)
               tm="十一月";
             if(StrToInt(tmonth)==12)
               tm="十二月";         
          }
         }
         delete fList;