date not datetime in datagrid while reading from db

  • Thread starter Thread starter Marcin Wiszowaty
  • Start date Start date
M

Marcin Wiszowaty

Hello,

I am reading into a dataset through a dataadapter. All drag+drop
implementation. I have a field in the db that is a datetime(8). whenever i
readin this field the datagrid displays the date plus 12:00 am. I want to
get rid of the 12:00am. I am sure that the db does not habe the hour in the
field. .Net is ading it on.

Thank you for your help
 
Marcin,

There is only a datetime type in Microsoft software. No DateTime. Even a SQL
shortDate is a DateTime field.

However there is no need to use it. There are plenty of possibilities to
skip the time part.

By instance DateTime.ToDate returns only the date.

Assuming that you are using WindowForms Datagrid (you did not write that)
you can use the columnstyles for that.

Cor
 
Sorry - Im using webforms ASP.net and vo2003

How would i use the DateTime.ToDate or columnstyles. i couldnt find
anything about it in the help.

thank you
 
Hi,

If you are using stored procedure to get data for dataset, then you can
use 'cast' and 'convert' functions of sql.

you can refer:
http://msdn2.microsoft.com/en-us/library/ms187928.aspx

In short, it would be great if you convert datetime to date before
binding it to grid..

Regards,
Mansi Shah.

I'm not sure that would solve the problem ... If you create a datetime
object in .NET and only specify the date, the time gets set to
defaults of midnight.

I think the best approach would be to format the gridview to get rid
of the time component
 
Hello,

the soulution i was looking for was adding

{0:d}

in:
rightclick on the datagrid
chose property builder
--> columns ' from the tabs on left
chose the column from the list on left
add it to the list on rigth
and add the {0:d} to the (data formating expresion) field

thank you for your help
 
Back
Top