大家好!我现在处于毕业设计中!我用了个Tcombobox跟数据库的一个表相连,表中的字段作为查询的条件,但在Tcombobox里显示的是英文(数据库的字段名为英文),但为了明了,我想改为中文显示!!请问怎样可以实现??
谢谢·!!
谢谢·!!
解决方案 »
- 电子转程序设计需要学些什么课程
- 如何检测字符串中是否有某些字符
- 请大家帮忙试试: 怀疑是delphi的bug..调用printer.fonts出错。 不好意思。分用光了。
- [求助]需要WindowsXP和Outlook的使用指南各1份,各给100分
- 这个SQL语句哪儿有错,我用ACCESS2000执行怎么不对?
- 制作安装程序的方法?
- 创建DLL文件,调用后更改系统分辨率,settimer创建的计时器失效了。
- 怎么用ListView1控件时,显示大的图标?
- 如何能够让skinengine的Form显示出标题的Caption(当Form.width比较小时)
- 求救!关于用Delphi 操作EXCEL?
- 我做的电脑通过模块给手机发短信,连接串口的本级能够正常发送,想了解客户端怎么操纵服务器的串口?
- 有没有类似msn那样的界面控件阿
我用TadoQuery连接数据库的!!!
但我的字段名是英文的,我想用中文显示,怎样实现啊?
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;谢谢你!!看看我怎样改才能实现啦!!
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);推荐第一种
谢谢你!!但是我不单单要查询姓名这个字段,我要那个表里的所有字段都可以作为查询的条件!
你给的那条sql语句应该只能查询姓名这个字段的吧 ?
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;
begin
combobox1.itemindex:=combobox2.itemindex;
end;选择的时候按2选,查询的时候按1查
select name as 姓名,sex as 性别,.......from table where ...
不就行了
由于我要做毕业设计才学delphi的,所以什么都不会!
你们别见笑了!!
现在行了!谢谢你们!!!