Retrieve DateTime SLQserver in DGV VS

1

I have a problem when it comes to showing the time record, everything works perfectly, except when the date is 00:00 (right at midnight).

Example of this case; 2018-07-26 00:00:00.000

The value recovers well in the program but at the time of showing it to the user in a dataGrid it only shows 2018-07-26 .

I applied a first idea; at the time of entering the record in BD added a second. leaving something like 2018-07-26 00:00:01.000 , doing this if it showed in dataGrid 2018-07-26 00:00 , but it does not help me since I alter the operation of the program in several checks.

The question is, how can I show that complete date (with the time) in dataGrid in cases of 00:00 ?

    
asked by Hector Lopez 24.07.2018 в 08:55
source

1 answer

1

The answer depends a bit on where you are defining the columns of your DataGridView . If you define them in the designer, you can access the property DefaultCellStyle :

Then you go to Format:

And then you can select a format from the available ones, or create your own:

In case you are not generating the columns from the designer, in your code you can put your format in the following way:

dataGrid.Columns[indice].DefaultCellStyle.Format = "dd/MM/yyyy HH:mm:ss";
    
answered by 24.07.2018 / 10:26
source