C#中的日期检索问题 [英] Date Retrieving problem in C#

查看:49
本文介绍了C#中的日期检索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

here is my code:

SqlDataAdapter dtd = new SqlDataAdapter("select Date From Sale ", conn);
           DataTable dt = new DataTable();
           dtd.Fill(dt);
           string tra = dt.Rows[0]["Date"].ToString();
           MessageBox.Show(tra);


我正在Sql Server数据库中检索日期.但是我的问题是日期列中不存在时间.然后时间也会与日期一起检索,然后时间不存在、、、
数据库日期列中的仅包含日期、、
Plz Help,


i am retrieving date in Sql server database.. But my problem is time does not exist in date column. then time also retrieve with date and then time does not exist,,,,
in database date column consist only date,,,
Plz Help,,,

推荐答案

所以这是一个问题,因为数据库中的列是一个简单的日期,根本没有时间部分,而且当您将其转换为datetime时也是如此或C#中的字符串,您会在日期中看到类似00:00:00的内容.
如果是这种情况,则可以按照显示日期的方式设置字符串的格式.例如,请参见 DateTime.ToString方法(字符串) [标准日期和时间格式字符串 [ ^ ]
So is the problem that since the column in the database is a simple date and no time portion at all and when you convert it to datetime or string in C# you see somethinh like 00:00:00 in the date.

If this is the case, then you can format the string the way you want to display the date. For example, see DateTime.ToString Method (String)[^] and Standard Date and Time Format Strings[^]


这篇关于C#中的日期检索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆