with datamodule1.qdepartment do
    begin
        close;
        sql.clear;
        sql.add('select * from department order by departmentid');
        open;
    end;
    while not datamodule1.qdepartment.eof do
    begin
        combobox4.items.Add(datamodule1.qdepartment.fieldbyname('departmentname').Value);
        datamodule1.qdepartment.Next; //数据后移
    end;
我通过如上代码将department表中的部门名循环添加到combobox4中..在一个信息录入窗口中,我通过选取combobox中的部门名,怎么将该部门名岁对应的部门号插入到一个表(该表含有部门号字段,即部门号字段为该表的外键)中呢?...//不要再告诉我又循环娶出来做比较然后再确定部门号啊,那太晕了哈..department table: (departmentid,departmentname,re)

解决方案 »

  1.   

    combobox4.items.AddObject(datamodule1.qdepartment.fieldbyname('departmentname').Value,TObject(编号)); 
    用AddObject添加Integer(combobox4.Items.Objects[combobox4.ItemIndex]
    这个是得到编号
      

  2.   

    with datamodule1.qdepartment do
        begin
            close;
            sql.clear;
            sql.add('select * from department order by departmentid');
            open;
        end;
        while not datamodule1.qdepartment.eof do
        begin
            combobox4.items.Add(datamodule1.qdepartment.fieldbyname('departmentname').Value,datamodule1.qdepartment.fieldbyname( 'departmentname ').Value);
            datamodule1.qdepartment.Next; //数据后移
        end;
    读取时,使用:
    如是整型integer(combobox4.items.Objects[Combobox4.ItemIndex])
    其余类型类似...