我有一个显示一些信息的gridview。其中一个信息是时间数据,例如:19:40:00.0000000。当我尝试使用 WriteXml 将我的 gridview 导出到 xml 文件时,我发现我的时间数据不正确,它看起来像: PT7H50M 。
--> 我的时间数据:gridview 中的 19:40:00.0000000 导出到 xml 文件后转换为:PT7H50M 为什么以及如何解决这个问题?
这是它在 xml 文件中的样子:
这是导出代码:
数据表 Rdt = 新数据表();数据集 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();
我试图通过将别名添加到每个选定的列来编辑我的 SQL 语句,但不幸的是它没有任何改进:
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 + "'