使用列过滤将 xml 加载到数据集中 [英] load xml into dataset with column filtering

查看:33
本文介绍了使用列过滤将 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. 仅显示必需的列.

这篇关于使用列过滤将 xml 加载到数据集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆