使用列过滤将 xml 加载到数据集中

使用列过滤将 xml 加载到数据集中

问题描述:

我想将 xml 加载到只有 2 列(名称、价格)的数据集

i would like to load xml into dataset with only 2 columns (name, price)

<?xml version="1.0" encoding="utf-8" ?>
<file>
<record>
    <name>A</name>
    <address>B</address>
    <date>12-12-2010</date>
    <price>100</price>
</record>
<record>
    <name>B</name>
    <address>C</address>
    <date>01-01-1999</date>
    <price>23</price>
</record>
</file>

这是我的 C# 代码:

here is my c# code:

string myXMLfile = "C:\\asdf.xml";
DataSet ds = new DataSet();

ds.ReadXml(myXMLfile);

dataGrid1.DataSource = ds;
dataGrid1.DataMember = "record";

显示所有记录.我能做些什么来过滤数据?

that displays all of the records. what can i do to filter the data?

过滤数据集/数据视图/数据表

filter dataset/dataview/datatable

或者读取特定的 xml 元素并将它们加载到数据集中?

or read specific xml elements and load them into dataset ?

还是过滤 datagrdview?

or filtering datagrdview?

非常感谢

  1. 设置您的dataGridView1.AutoGenerateColumns 为 false.
  2. 仅显示必需的列.