我用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;{展开}