我用delphi7+sqlserver2000+ado做一个数据库程序现在遇到下面一个问题,请各位高手帮小弟解决:表1:person                        表2   department
  id char(10)//编号                      id smallint //部门代码
  name char(10)//姓名                    description char(20)//部门描述
  department smallint//部门代码  下面是一个表格(dbgrid)显示了两个数据:
  编号     姓名     部门
  1000     张三     人事部
  10001    李四     后勤
下面我想在表格中增加一个数据,在部门这里根据departmeng有一个下拉列表,可以从中选择部门描述,当我把这条新加的记录保存到person表中的时候,应该怎么做呢?在person中部门是一个代码,但在表格中这里是部门描述,难道我要一个一个的判断吗?请个位高手给出相应的sql语句,小弟不胜感激!!!!!!!!

解决方案 »

  1.   

    声明
    procedure P_B_shifdyGetText(Sender: TField;var Text: String; DisplayText: Boolean);函数
    procedure TForm_Print_qicai.P_B_shifdyGetText(Sender: TField;
      var Text: String; DisplayText: Boolean);
    begin
      try
          if (Sender as TField).Value = 'true' then Text:= '是'
            else Text:= ''; //    否
      except
      end;
    end;调用(可在控制DBGrind 宽度的函数中写如下代码,注意try 一下。)
    Form_DM_01_10.ADOQ_BarCode.FieldByName('B_shifdy').OnGetText:= P_B_shifdyGetText;  // 显示汉字