大家好!我现在处于毕业设计中!我用了个Tcombobox跟数据库的一个表相连,表中的字段作为查询的条件,但在Tcombobox里显示的是英文(数据库的字段名为英文),但为了明了,我想改为中文显示!!请问怎样可以实现??
谢谢·!!

解决方案 »

  1.   

    combobox的选项显示的字段名吗?你用什么来连接数据库的?
      

  2.   

    是啊!!用Tcombobox显示数据表的字段名!!
    我用TadoQuery连接数据库的!!!
    但我的字段名是英文的,我想用中文显示,怎样实现啊?
      

  3.   

    这是combobox的语句
    procedure TGYSWH.ComboBox1DropDown(Sender: TObject);
    var
      i: Integer;
    begin
    combobox1.Clear;
      DM.combobox1.Close;
      DM.combobox1.SQL.Text := 'select * from Order_vendor';
      DM.combobox1.Open;
      for i := 0 to DM.combobox1.FieldDefList.Count - 1 do
        combobox1.Items.Add(DM.combobox1.FieldDefList.FieldDefs[i].Name);
      if combobox1.Items.Count > 0 then combobox1.ItemIndex := 0;end;这个按的查询按钮的语句!!
    procedure TGYSWH.Button1Click(Sender: TObject);
       begin
            try
              with DM.Querytemp do
              begin
                SQL.clear;
                SQl.Text := 'select * from Order_Vendor where ' + trim(combobox1.Text) +
                  ' like '
                  + #39 + '%' + trim(edit1.text) + '%' + #39;
                Close;
                Active := False;
                prepared := False;
                prepared := True;
                Active := True;
                GYSWH.FYDBGrid1.DataSource := DM.dsQuerytemp;
              end;
            except
              MyError('查询分析错误');
            end;
          end;谢谢你!!看看我怎样改才能实现啦!!
      

  4.   

    第一个办法 直接改SQL语句
    select * 改成 select name as 姓名 ...... 
    这样程序其他地方可以不动
    第二个办法 可以在 数据集打开的时候(某个事件里吧 忘了)
    写 字段的DisplayLabel 
    这样
     fieldbyname('name').DisplayLabel :='姓名';
    ...
    ...
    所有字段都要写
    然后
    combobox1.Items.Add(DM.combobox1.FieldDefList.FieldDefs[i].Name);
    改成
    combobox1.Items.Add(DM.combobox1.FieldDefList.FieldDefs[i].DisplayLabel);推荐第一种
      

  5.   

    To:dh9450(谁有我菜)
    谢谢你!!但是我不单单要查询姓名这个字段,我要那个表里的所有字段都可以作为查询的条件!
    你给的那条sql语句应该只能查询姓名这个字段的吧 ?
      

  6.   

    将要查询的字段的中文名添加到 combobox1中然后可以添加一个方法嘛,例如:
    function tform1.GetFieldNameByChineseName(
      strChineseName: string): string;
    begin
      if Trim(strChineseName) ='' then
      begin
        Result := '';
        exit;
      end;
      if  Trim(strChineseName)    = '工程编号' then
        Result := 'PAPERCODE'
      else if Trim(strChineseName) = '日期' then
        Result := 'PROJECTDATE'
      else if Trim(strChineseName) = '工作类型' then
      begin
        if RdBtnTaskPaper.Checked then   Result := 'WORKTYPE'
        else Result := 'TYPE';
      end
      else if Trim(strChineseName) = '工程名称' then
        Result := 'PROJECTNAME'
      else if Trim(strChineseName) = '签发部门' then
        Result := 'SIGNDEPT'
      else if Trim(strChineseName) = '签发人' then
        Result := 'SIGNER'
      else if Trim(strChineseName) = '经办人' then
        Result := 'TRANSACTOR'
      else if Trim(strChineseName) = '联系项目' then
        Result := 'RELATIONDEPT'
      else if Trim(strChineseName) = '主送单位' then
        Result := 'MAINSENTTEAM'
      else if Trim(strChineseName) = '部门主管' then
        Result := 'DEPTHEADER' ;
    end;然后查询就可以是:
    procedure TGYSWH.Button1Click(Sender: TObject);
       begin
            try
              with DM.Querytemp do
              begin
                SQL.clear;
                SQl.Text := 'select * from Order_Vendor where ' + trim(GetFieldNameByChineseName(combobox1.Text)) +
                  ' like '
                  + #39 + '%' + trim(edit1.text) + '%' + #39;
                Close;
                Active := False;
                prepared := False;
                prepared := True;
                Active := True;
                GYSWH.FYDBGrid1.DataSource := DM.dsQuerytemp;
              end;
            except
              MyError('查询分析错误');
            end;
          end;
      

  7.   

    呵呵,你不会select name as '姓名',sex as '性别',........from 表!
      

  8.   

    用两个combobox,一个真的-隐藏combobox1,一个解释用的-显示combobox2procedure TForm1.ComboBox2Change(Sender: TObject);
    begin
      combobox1.itemindex:=combobox2.itemindex;
    end;选择的时候按2选,查询的时候按1查
      

  9.   

    真晕啊 就是啊 一个个的写过来啊 
    select name as 姓名,sex as 性别,.......from table where ...
    不就行了
      

  10.   

    真的谢谢你们!!
    由于我要做毕业设计才学delphi的,所以什么都不会!
    你们别见笑了!!
    现在行了!谢谢你们!!!