2 Replies - 4645 Views - Last Post: 02 July 2013 - 06:40 AM Rate Topic: -----

#1 jagman82  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 24-February 10

convert xml datetime UTC to datetime.short with no UTC

Posted 01 July 2013 - 06:46 PM

I've been hammering away at this code but cannot find a resolution. The XML provides a datetime with UTC attached. The Informix database, using the ODBC driver, does not allow that long of a date time. Am I missing something? I have tried utilizing reqDateTime = xr.ReadElementContentAsDateTime(); instead of reqDateTime = xr.ReadElementContentAsString();.

 
private void Form1_Load(object sender, EventArgs e)
        {
            //XmlReader information

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;

            settings.IgnoreProcessingInstructions = true;

            settings.IgnoreWhitespace = false;



            string DocID = null;

            int elementCount = 0;

            string reqID = null;

            string reqDateTime = null;

            string empName = null;

            string[] fileEntries = Directory.GetFiles("\\XML\\", "*.xml");

            foreach (string fileName in fileEntries)
            {

                XmlReader xr = XmlReader.Create(fileName, settings); //reads XML from folder

                while (xr.Read())
                {
                    try
                    {
                        //process file line here
                    }
                    catch (Exception ex)
                    {

                    }

                    if (xr.NodeType == XmlNodeType.Element && xr.Name == "nc:DateTime")
                    {

                        reqDateTime = xr.ReadElementContentAsString();

                    }

                    if (xr.NodeType == XmlNodeType.Element && xr.Name == "nc:IdentificationID")
                    {

                        elementCount++;

                        DocID = xr.ReadElementContentAsString();

                        if (elementCount == 1)
                        {

                            reqID = DocID;

                        }

                        if (elementCount == 3)
                        {

                            empName = DocID;



Is This A Good Question/Topic? 0
  • +

Replies To: convert xml datetime UTC to datetime.short with no UTC

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3540
  • View blog
  • Posts: 10,959
  • Joined: 05-May 12

Re: convert xml datetime UTC to datetime.short with no UTC

Posted 02 July 2013 - 06:25 AM

So you replaced the line 46 with reqDateTime = xr.ReadElementContentAsDateTime();. (I'm assuming that you also changed the type of reqDateTime to DateTime on line 21.) That should get you the data in a much more easily manipulated form.

So where is your code where you are trying to put the data into your Informix database? Unless you are converting the DateTime back into a string, it shouldn't matter since you are using parameterized queries. You are using parameterized queries, right?
http://www.dreaminco...ery-a-database/

This post has been edited by Skydiver: 02 July 2013 - 06:25 AM

Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3540
  • View blog
  • Posts: 10,959
  • Joined: 05-May 12

Re: convert xml datetime UTC to datetime.short with no UTC

Posted 02 July 2013 - 06:40 AM

I moved this topic from "Advanced C#" forum to the "C#" forum since I feel that this fits in better with the level of questions asked in this area. Typically "Advanced C#" covers more of designs and techniques of programming in C# rather than mechanics of programming in C#.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1