简体   繁体   English

数据表中的XML模式错误

[英]Wrong xml schema from datatable

I try to write an xml file from a datatable. 我尝试从数据表写入xml文件。

for (int i = 0; i < ValToAppendDt.Count; i++)
        {
            DataRow row = ResultDT.NewRow();
            row[i] = ValToAppendDt[i].ToString();
            ResultDT.Rows.Add(row);
        }
        ResultDT.WriteXml(@"\\blabla\" + Environment.MachineName + ".xml");

This results in this xml file: 这将产生以下xml文件:

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
  <ResultsTable>
    <PC_Name>blabla</PC_Name>
  </ResultsTable>
  <ResultsTable>
    <PC_Network_Card>blabla</PC_Network_Card>
  </ResultsTable>
  <ResultsTable>
    <PC_Mac>blabla</PC_Mac>
  </ResultsTable>
</DocumentElement>

So when I try to import this into excel, the first value appears in A1, the second in B2, third in C3... 因此,当我尝试将其导入excel时,第一个值出现在A1中,第二个值出现在B2中,第三个值出现在C3中...

I'd like to have them in A1, B1, C1... But I can't fiind a way 我想将它们放在A1,B1,C1中...但是我找不到办法

I was mystaking in my for Loop... I changed it to : 我在for Loop中很着迷...将其更改为:

DataRow row = ResultDT.NewRow();
for (int i = 0; i < ValToAppendDt.Count; i++)
    {            
        row[i] = ValToAppendDt[i].ToString();            
    }
ResultDT.Rows.Add(row);

working fine now... 现在工作正常...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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