开发者

SQL Column of type Date comes with Time

开发者 https://www.devze.com 2023-02-28 16:29 出处:网络
Hi I have an App which works with a DB. And I have one table where one of the columns is of type Date, and in the DB it\'s fine. If I do a query to the table in question, the table will show only the

Hi I have an App which works with a DB. And I have one table where one of the columns is of type Date, and in the DB it's fine. If I do a query to the table in question, the table will show only the Dates without time in that Column.

But something goes wrong when I get this table into my App and put it in a DataTable. When I do this Column of type Date will have the Date but with the Time and in all Dates appear for example like this (24-04-2011 00:00:00). How is this possible if the Column type in the DB is Date?

I am working with MS SQL Server in the server side, and with C# in App side.

开发者_StackOverflow社区

Thanks in advance!


You have to format your column's value .. The way differs depending on which control you are using ..

DataGridView has a collection of DataGridViewColumn. The DataGirdViewColumn has a property of the type DataGridViewCellStyle that has itself a string property called Format. You have to assign a value to the Format property to format the value showed in your column. In your case the appropriate value to assign is "d".

You can assign a value for the mentioned property at design time or runtime.


Just for information:

SQL Server has a Date data type that takes only date values without time.

C# has a only a DateTime data type wich consists of a date portion and a time portion as well. No data type for date or time seperately in C#. However, you can get the date portion or the time portion as strings using DateTime.ToShortDateString and DateTime.ToShortTimeString respectively ..


The datatype for dates in C# is DateTime, which invariably comes with a time. You can just ignore the time as it's insignificant (and always 00:00:00, for that matter).


While there is a date type in SQL Server, there is no such thing in .NET framework itsekf. Therefore, it uses whatever comes closer, which happens to be DateTime.

All in all, this is purely presentation issue: just format your output propery and you'll be fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消