reformat current DateTime object

K

Kevin

Hi All

I have a DateTime object called dt. the format of dt.Date
is mm/dd/yyyy. How can I change this format to dd/mm/yyyy
and still keep it as a DateTime object so that I can run
this following SQL query :

UPDATE WorkRoster SET DateWorking = ? WHERE DateWorking IS
NULL

I have added a parameter to hold the date.

I have tried to make my parameter = dt.ToString("d"), but
when the Update statment runs I get and OLEDbException
that is thrown, telling me that the Paramter does not have
a default value. I assuming it's maybe telling me this
because I tried to enter a string in the parameter?

The database is an Access 2000 DB and the field's datatype
is ShortDate.

How can I solve this problem?

Any help is much appreciated
TIA
Kevin
 
J

Jon Skeet [C# MVP]

Kevin said:
I have a DateTime object called dt. the format of dt.Date
is mm/dd/yyyy.

No it's not. Not really. The format of dt.Date is another DateTime.
DateTimes themselves have no explicit format.
How can I change this format to dd/mm/yyyy
and still keep it as a DateTime object so that I can run
this following SQL query :

UPDATE WorkRoster SET DateWorking = ? WHERE DateWorking IS
NULL

I have added a parameter to hold the date.

In that case just set the value to dt.Date, which is a DateTime itself
- there's no need to format it at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top