简体   繁体   中英

Xml file show incorrect time data after exported it from gridview

I have a gridview which display some information. One of those information is a time data like: 19:40:00.0000000. When I tried to export my gridview to xml file using WriteXml I found incorrect data for my time, it is look like : PT7H50M .

--> My time data : 19:40:00.0000000 in gridview converted to : PT7H50M after export it to xml file Why and How can I solve this problem ?

this is a time data in my gridview : 我的时间数据在GridView中

This is what it look like in xml file :

在此处输入图片说明

This is the code of export :

DataTable Rdt = new DataTable(); DataSet Rds = new DataSet();

                    Rdt = (DataTable)GV_Report.DataSource;
                    Rds.Tables.Add(Rdt.Copy());

                    Rds.WriteXml(@"c:\Reporting\Work_Hours_Report.xml", System.Data.XmlWriteMode.IgnoreSchema);

                    XmlDocument doc = new XmlDocument();
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    XmlWriter writer = XmlWriter.Create(@"c:\Reporting\ReportType.xml", settings);
                    writer.WriteStartDocument();
                    writer.WriteComment("This file is generated by the program...Please do not change this file!!");
                    writer.WriteStartElement("ReportBut");
                    writer.WriteElementString("ButType", "Work_Hours_Report");
                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    writer.Flush();
                    writer.Close();

I tried to edit my SQL statement by adding Aliases to each selected columns but unfortunately it does not make any improvement :

select CAST(DATEADD(MILLISECOND,SUM(DATEDIFF(MILLISECOND,0,CAST(ISNULL([Total_H],'00:00:00') AS DATETIME))),0) AS TIME) as '1',sum([HTotal]) as '2',sum([MTotal]) as '3',CAST(DATEADD(MILLISECOND,SUM(DATEDIFF(MILLISECOND,0,CAST(ISNULL([PH_Total],'00:00:00') AS DATETIME))),0) AS TIME) as '4',sum([PH]) as '5',sum([PM]) as '6',CAST(DATEADD(MILLISECOND,SUM(DATEDIFF(MILLISECOND,0,CAST(ISNULL([AH_Total],'00:00:00') AS DATETIME))),0) AS TIME) as '7',sum([AH]) as '8',sum([AM]) as '9'  FROM [QAMNI].[dbo].[tbl_WorkHours_Details]  where [Date] between '" + DF + "' and '" + DT + "' and [C_ID] ='" + txt_C_ID.Text + "'

According to the advance of Mr. @ Flynn1179

I changed the XmlWriteMode from IgnoreSchema to WriteSchema and the result was correct without any xsd: dayTimeDuration represents duration of time expressed as a number of days, hours, minutes, and seconds. The format of xsd: dayTimeDuration is PnDTnHnMnS as in my Reporting file, once I change it I got the time exactly as I select from my database without any change in format. Thank you all of you for help. This is my XML file after changing the XmlWriteMode from IgnoreSchema to WriteSchema :

在此处输入图片说明

It still display as xsd format but when I print it out to end user using crystal report it give me correct time format as (“hh:mm:ss”) :

在此处输入图片说明

This is what I change in my code:(only changing the XmlWriteMode)

 Rds.WriteXml(@"c:\Reporting\WorkHours_Report.xml", System.Data.XmlWriteMode.WriteSchema);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM