简体   繁体   English

Sql数据类型日期也显示时间

[英]Sql data type date showing time as well

I made a DB and have a few tables with dates like joining dates, register date etc so once I select all those table inside SQL it shows me date which it should but since this DB is connected to winforms application and if I fetch any of those tables data on a textbox, gridview or reportviewer it shows me date but with a default time which it shouldn't.我创建了一个数据库,并有一些带有日期的表,例如加入日期、注册日期等,因此一旦我在 SQL 中选择了所有这些表,它就会向我显示它应该显示的日期,但是由于该数据库已连接到 winforms 应用程序,如果我获取了其中的任何一个在文本框、gridview 或 reportviewer 上的表格数据它向我显示日期但它不应该显示默认时间。

Is there something that I need to do once I connect it to my Winforms application?一旦我将它连接到我的 Winforms 应用程序,我需要做些什么吗?

One of my table with date:我的一张带有日期的表:

CREATE TABLE Admin_Details 
(
    Id INT PRIMARY KEY IDENTITY(1,1) NOT NULL,
    First_Name VARCHAR(15) NOT NULL,
    Last_Name VARCHAR(15) NOT NULL,
    Login_User_Name VARCHAR(20) UNIQUE NOT NULL,
    Login_Password VARCHAR(25) NOT NULL,
    Father_Name VARCHAR(20) NULL,
    Joining_Date DATE NOT NULL
)

I just want the see date in textbox, gridview and reports and remove time from it.我只想要在文本框、gridview 和报告中查看日期并从中删除时间。

I have googled it and looked for answers here but couldn't find it anywhere.我在谷歌上搜索并在这里寻找答案,但在任何地方都找不到。 I believe this is a very basic thing that's why it's not there but I really want to know this so if anyone knows if this is answered anywhere before so please share the link.我相信这是一个非常基本的事情,这就是为什么它不在那里,但我真的很想知道这一点,所以如果有人知道之前是否有人回答过这个问题,请分享链接。

The Sql Server equivalent C# object is DateTime type. Sql Server 等效的C#对象是DateTime类型。 There is no Date type in C#. C# 中没有 Date 类型。 That is why you have a default time with the date.这就是为什么你有一个默认的日期时间。

If you want to display the date only then you can do this before setting the value in the text box: yourObject.ToString("MM/dd/yyyy, CultureInfo.InvariantCulture);如果您只想显示日期,则可以在设置文本框中的值之前执行此操作: yourObject.ToString("MM/dd/yyyy, CultureInfo.InvariantCulture);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM