如何将SQL SERVER数据库中的bit字段在DBGRid中显示为“是”或“否”?

douer2002 2003-10-21 11:09:41
如题
...全文
200 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
douer2002 2003-11-04
  • 打赏
  • 举报
回复
adoquery中的永久字段的displayvalues属性值是什么啊?在哪儿设置啊?
konhon 2003-11-01
  • 打赏
  • 举报
回复
adoquery中的永久字段的displayvalues属性值设成 是,否 就行了,一句代码也不用
更改: “是”与“否”中间是分号
delphiseabird 2003-11-01
  • 打赏
  • 举报
回复
更改: “是”与“否”中间是分号
delphiseabird 2003-10-28
  • 打赏
  • 举报
回复
adoquery中的永久字段的displayvalues属性值设成 是,否 就行了,一句代码也不用
hmily1688 2003-10-25
  • 打赏
  • 举报
回复
伴水都回答了,就不答了
Frewin 2003-10-25
  • 打赏
  • 举报
回复
select '是否' = (case 字段名 when 0 then '否' when 1 then '是' end)
from tablename
PJANE 2003-10-25
  • 打赏
  • 举报
回复
在查询时可直接按以上的语句取值,则在查询到的内容里有此一项,可用DBGRID直接关联此项
select sexgb = case sex when 0 then '男' when 1 then '女' end
from employee
PJANE 2003-10-25
  • 打赏
  • 举报
回复
select sexgb = case sex when 0 then '男' when 1 then '女' end
from employee
ujjcel 2003-10-22
  • 打赏
  • 举报
回复
建议用Ehlib,我就是这么用的,很方便的.
SunKinXing 2003-10-22
  • 打赏
  • 举报
回复
设数据集adotable的字段为静态字段:

在方法中:
procedure TForm1.ADOTable1SEXGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
if Sender.Asinteger = 1 then
Text:='是' else Text:='否';
end;
zswangII 2003-10-22
  • 打赏
  • 举报
回复
'"否";"是";"是"' -> '"是";"是";"否"' //更正下~~
zswangII 2003-10-22
  • 打赏
  • 举报
回复
同意~~
>回复人: afei78223(阿飞) ( ) 信誉:101 2003-10-21 18:18:00 得分:0
> (Field As TBooleanField).DisplayValues := Format('%s;%s ',['是','否']);


VCL Reference
TBooleanField.DisplayValues

TBooleanField See also

Controls how the Boolean field is translated to and from display format.

property DisplayValues: string;

Description

Use DisplayValues to specify strings the field uses to represent Boolean values. Use any pair of phrases, separated by a semicolon. For example, to have the True and False values correspond to the letters T and F, respectively, set DisplayValues as follows:

Table1LogicalField.DisplayValues := 'T;F';

Similarly, to set the values of True and False to the strings Yes and No, set DisplayValues to

Table1LogicalField.DisplayValues := 'Yes;No';

The string associated with True or False can be an empty string. To set the value for True to an empty string, set DisplayValues to a string that begins with a semicolon. For example, to associate False with the string Fail, and True with an empty string, set DisplayValues to

Table1LogicalField.DisplayValues := ';Fail';

To associate False with an empty string, set DisplayValues to the string for True, with no semicolon at all.

The strings associated with True and False by DisplayValues appear in data-aware controls when they display the data for a Boolean field. If one of the strings is an empty string, Boolean values associated with that string appear blank in data-aware controls.

These strings are also used when getting or setting the Boolean field抯 AsString property.


//参考如下代码~~
//也可以静态设置~~
procedure TForm1.Table1AfterOpen(DataSet: TDataSet);
begin
TNumericField(DataSet.FieldByName('数值字段')).DisplayFormat := '"否";"是";"是"';
TBooleanField(DataSet.FieldByName('逻辑字段')).DisplayValues := '是;否';
end;
douer2002 2003-10-22
  • 打赏
  • 举报
回复
OnGetText & OnSetText是哪个控件的事件啊?
douer2002 2003-10-21
  • 打赏
  • 举报
回复
什么计算字段啊,是什么意思啊
huojiehai 2003-10-21
  • 打赏
  • 举报
回复
用计算字段可以适应不同的数据库
whitetiger8 2003-10-21
  • 打赏
  • 举报
回复
是啊。就这样做。没什么难的
flfljh 2003-10-21
  • 打赏
  • 举报
回复
同意
delphi_xizhousheng 2003-10-21
  • 打赏
  • 举报
回复
设计期写onsettext/onGetText事件可以
新建一个计算字段也可以 dataset.CalcFields事件
afei78223 2003-10-21
  • 打赏
  • 举报
回复
(Field As TBooleanField).DisplayValues :=Format('%s;%s ',['是','否']);
cjfzy 2003-10-21
  • 打赏
  • 举报
回复
在sql语句中用case:
select field1,case field2 when 1 then 是,when 2 then 否 end,field3……
加载更多回复(8)

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧