我从一个简单的 DataTable 开始,我在其中写入了一个 XML 文件。下次程序运行时,我想检查 XML 文件是否存在,并读取它。
看起来写 xml 很好,我相信阅读它很好,但我似乎无法从 DataSet 中获取任何数据。
ds.WriteXml(@"C:\Computers\config.xml");
if (File.Exists(@"C:\Computers\config.xml"))
{
ds.ReadXml(@"C:\Computers\config.xml");
//comboBox.Items.Add(ds.Tables[0].Rows[0][0].ToString()); doesn't work
comboBox.Items.Add(ds.Tables[0].Rows.Count); //this counts 3 rows
}
我收到此错误。
System.Data.dll 中出现“System.IndexOutOfRangeException”类型的未处理异常
附加信息:找不到第 1 列。
这是我的 XML 文件
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table1>
<Name>Test1</Name>
<Version>1.1.1.1</Version>
<Code />
<Location>C:\Computers\test.txt</Location>
</Table1>
<Table1>
<Name>test2</Name>
<Version />
<Code />
<Location />
</Table1>
<Table1>
<Name>test3</Name>
<Version />
<Code />
<Location />
</Table1>
</NewDataSet>
我只是想从每一行中获取“名称”字段,我做错了什么?