tags:

views:

44

answers:

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>

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

or read specific xml elements and load them into dataset ?

or filtering datagrdview?

many thanks

+1  A: 
  1. Set your dataGridView1.AutoGenerateColumns to false.
  2. Display only required columns.
KMan
sorry, my mistake. it is dataGrid in win form
Kiddo
A: 

How about using LINQ to XML to read from the XML XElement.Load(@"C:\asdf.xml"); Then using LINQ to filter the results and call a ToList... Why do you need to use a dataset?

GordonB
that's a good ideacan i bind datasource = results.Tolist();?
Kiddo
yes, datasource can be a list. Using a dataset to contain the data seems a bit OTT.
GordonB