XML datetime

  • Thread starter Thread starter Jason Huang
  • Start date Start date
J

Jason Huang

Hi,

In my C# windows form application, I can write a dataset to an XML file.
But everything in that XML are String type.
Is is possible to write a dataset to an XML file, so that the DateTime and
Int is still DateTime and Int in the XML?
Thanks for help.



Jason
 
In my C# windows form application, I can write a dataset to an XML file.
But everything in that XML are String type.
Is is possible to write a dataset to an XML file, so that the DateTime
and Int is still DateTime and Int in the XML?

Sure. Just format the data into a string, using an appropriate format for
the information you want to save. For an int, this would probably be the
default ToString() behavior, unless you had some reason to make it look
different in the XML file. For a DateTime, you would use a format that
preserves the portions of the DateTime that are important to you.

When reading the XML back in, just use the Parse() methods to recover the
original data from the strings.

Finally, keep in mind that I've never used the built-in .NET XML handling
classes. Given that the project Settings property handles this sort of
thing for you, it's possible that the built-in .NET XML stuff has a way to
do this automatically rather than making you Format and Parse yourself.
Maybe someone else will point out a better way than the above.

Pete
 
Thanks Peter.
I output the DateTime field to the format of 'YYYY/MM/DD', then it works
fine.
 

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

Back
Top