我用dephi7.0制作了一个查询窗体,在这个窗体中我想通过查询数据库的两个表中的关联项,如在客户表中客户编号与开户表中的客户编号,在输出项中,我用了一个listbox控件在items中填了两个表的几项,但是我在数据库里建表时各项都用字母建的,如客户编号就是khbh,我想在查询时,在输出项里显示的是中文的客户编号,而不是我现在的字母khbh
在查询按钮中用什么语句能把字母khbh转化成中文的客户编号。代码如下
procedure TForm1.Button1Click(Sender: TObject);
var
Selectstr:string;{输出条目信息}
i:integer;
begin
if Listbox1.SelCount=0 then{如果输出项数目为0,则要求再选}
begin
showmessage('请选择输出项');
exit;{退出此操作}
end;
Selectstr:='';{清空条目信息}
for i:=0 to listbox1.Items.Count-1 do
if(listbox1.Selected[i]) then
Selectstr:=Selectstr+listbox1.Items.Strings [i]+',';{逐个加入查询输出条目}
Selectstr:=Selectstr+',';
Delete(Selectstr,length(Selectstr)-1,2);{删除最后的‘, ’字符}query1.Close;{首先关闭query1}
query1.SQL.Clear;{置空SQL语句}
query1.SQl.Add('Select '+Selectstr);{假如输出条目}
query1.SQl.Add('FROM shebeibiao,kaihubiao');{源表}
query1.SQl.Add('where shebeibiao.sbxh=kaihubiao.sbxh');
if(Edit1.text<>'') then{员工姓名查询条件}
query1.SQl.Add(' AND sbbh='''+edit1.Text+'''');
if(Edit2.text<>'') then{部门查询条件}
query1.SQl.Add(' AND sbzt='''+edit2.Text+'''');
if(Edit3.text<>'') then
begin                               {员工工资查询条件}
query1.SQl.Add(' AND azdd='''+edit3.text+'''');
end;
query1.Prepare;{准备展开query1语句}
query1.Open;{展开}

解决方案 »

  1.   

    我现在不知道用什么语句才能把listbox控件在items的字母变成汉字,我要显示的中文编号是客户编号,也就是把listbox控件在items的khbh变成中文编号是客户编号。
      

  2.   

    在sql语句中用
    select khbh as 客户编号,....
    from .....
      

  3.   

    谢谢你firetoucher(蹈火者) ,你给我的建议我用了以后,在运行时还是出错,提示出错信息是我的列名客户编号无效,我想是不是因为我在数据库里建的数据表的各项是字母的原因呢?
      

  4.   

    给你个hint,这个我实现过,搞一个属性让用户设置
    如下面样式姓名=name
    客户编号=khbh
    客户名称=khmc
    ...
    然后你解析就可以了。
    具体怎么解吸相信你写的出这样的函数。
      

  5.   

    定义两个相对应的数组
        Show: array [0..i] of string; //存储中文显示的名字,i与listbox的index对应
        Field: array [0..i] of string; //存储英文的字段名,选中中文的时候直接换到字段数组就可以了,这样还可以扩充,根据需要自己定义大小。
      

  6.   

    var i:integer;
    begin
    for i:=0 to (adoquery1.FieldCount-1) docombobox1.Items.Add(adoquery1.recordset.fields[i].name);
    end;
    SQL为select cid as 客户编号,why as 原因 from jiangcheng;
    要是可怜我给点分给我吧!