views:

81

answers:

2

i have loaded an xml file to a dataset successfully (i can display it in a datagrid), i'd like to load it in several textboxes (about 10 or 12).

the xml has about 60 fields, and i'm not that familiar with getting their names (though i know which ones i want).

that's what i have:

Dim ds As New DataSet
ds.ReadXml(<PATH>)

a glimpse of one part of the xml:

<ide>   
 <cUF>35</cUF>   
 <cNF>623670848</cNF>
</ide>
<emit>
 <CNPJ>06949571000153</CNPJ> 
 <xFant>TSA</xFant>

i want (example)
cUF from IDE
cFant from tsa

i've got txt1 and txt2 as textboxes, what do i do to get those?

+1  A: 

Have a look a the System.XML namespace, and then do something like this, using a correct XPath expression in the SelectSingleNode() function:

private XmlDocument _doc = new XmlDocument();
_doc.Load(HttpContext.Current.Request.MapPath("~/yourdocpath.xml"));
XmlNode n = _doc.SelectSingleNode("ide/cuf");

and then to set the textbox:

txt1.Text = n.InnerText;
flesh
+1  A: 

if you've got the data in a dataset you can get the information out in a few ways. There is the way flesh recomended for reading it directly from the XML, and there is the table/row/column method for getting it out of the dataset.

If you know the column names at design time:

Theory:

txt1.Text = DS.Tables[<tablename>].Rows[<rowID>].ItemArray[<ColumnIndex>].ToString();

Practice:

txt1.Text = DS.Tables["ide"].Rows[0].ItemArray[0].ToString();

If you do not know the column names at design time:

Theory:

txt1.Text = DS.Tables(<tableID>).Rows(<rowID>).Item(<ColumnID>)

Practice:

txt1.Text = DS.Tables[0].Rows[0].ItemArray[0].ToString();

careful using the indexed numbers though... sometimes they can get you into trouble.

Jrud
which kind of trouble? like getting a different kind of xml and displaying the wrong way ?
MarceloRamires
exactly. We've accidentally changed the order of the columns on the SQL server before. This will change the order of the column indexes and require recoding. Some DBMS systems will return data in the order specified by the columns on your query, others will return the columns in order specified internally... so keep an eye out for problems like this when working with the column index.
Jrud