c#中datagridview显示格式问题

fanbo 2009-09-01 05:03:51
在sql数据库中,一个时间被存放成了int型,例如09:12:10被存储成为91210。
在现在的程序中,我将直接select出来该数据,然后用datagridview显示,显示的自然就是91210,可是现在老板想显示成为
9:12:10。我该怎么做,是否可以在select的语句中做些修改,还是应该做其他的处理?
...全文
204 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2009-09-01
  • 打赏
  • 举报
回复
this.dataGridView1.Columns[""].DefaultCellStyle.Format = "hh-mm-ss";
或在SQL截取字符串取值再绑定控件
hillfeet 2009-09-01
  • 打赏
  • 举报
回复
就使用DateTime来存放不好吗?格式化显示就可以了。DateTime实际上是一个数值,比字符又小又快。
wb1125 2009-09-01
  • 打赏
  • 举报
回复
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
dataGridViewCellStyle1.Format = "00:00:00";
this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
踏雪听雨 2009-09-01
  • 打赏
  • 举报
回复
自己加逻辑了
andyking_ 2009-09-01
  • 打赏
  • 举报
回复
select left(datetime,1,2)+':'+left(datetime,3,4)+':'+left(datetime,5,6) from....
给你个例子,你自己再加点逻辑进去
lsj_zrp 2009-09-01
  • 打赏
  • 举报
回复
select case len(iTime) when 6 then left(iTime,2) else left(iTime,1) end+':'+left(right(iTime,4),2)+':'+right(iTime,2) from table1
wh_wangjun 2009-09-01
  • 打赏
  • 举报
回复

int aTime=91210;
string sTime = aTime.ToString("D6");
sTime = sTime.SubString(0,2)+":"+sTime.SubString(2,2)+":"+sTime.SubString(4,2);
//sTime = 09:12:10
ncjcz 2009-09-01
  • 打赏
  • 举报
回复
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
dataGridViewCellStyle1.Format = "00:00:00";
this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
北京的雾霾天 2009-09-01
  • 打赏
  • 举报
回复
就使用DateTime来存放不好吗?格式化显示就可以了。DateTime实际上是一个数值,比字符又小又快。
zhangyanyang 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 angel6709 的回复:]
能行吗????
如果是9:01:00存成什么?
90100?
[/Quote]
发一下具体格式?
不出咯的话时间字符串转换可以的
muyebo 2009-09-01
  • 打赏
  • 举报
回复
看看能不能用datetime.parse转
dancingbit 2009-09-01
  • 打赏
  • 举报
回复
设置该列的DefaultCellStyle属性的Format属性。
angel6709 2009-09-01
  • 打赏
  • 举报
回复
能行吗????
如果是9:01:00存成什么?
90100?

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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