rp
asked on
Show selected xml in gridview from linq query
I have this code return all elements of each "line" element in "InvoiceNum". But returns each one at a time. I need to return all elements of each line (ProductId, Description,Quantity) to a unique row and then show in datagridview.
<Documents>
<Sales>
<Total>81678.600000</Total>
<Invoice>
<InvoiceNum>153</InvoiceNum>
<Date>2013-03-01</Date>
<Customer>2589</Customer>
<Line>
<ProductId>AT.02-2584</ProductId>
<Description>Product 1</Description>
<Quantity>1.000</Quantity>
<UnitPrice>265.140000</UnitPrice>
</Line>
</Invoice>
<Invoice>
<InvoiceNum>154</InvoiceNum>
<Date>2013-03-01</Date>
<Customer>2589</Customer>
<Line>
<ProductId>AT.02-2584</ProductId>
<Description>Product 1</Description>
<Quantity>1.000</Quantity>
<UnitPrice>265.140000</UnitPrice>
</Line>
<Line>
<ProductId>AT.02-2599</ProductId>
<Description>Product 2</Description>
<Quantity>1.000</Quantity>
<UnitPrice>85.100000</UnitPrice>
</Line>
</Invoice>
</Sales>
</Documents>
Dim xdoc As XDocument = XDocument.Load("C:\Test\test.xml")
Dim query = (From xe In xdoc.Descendants("Invoice") _
Where (xe.Element("InvoiceNum").Value = "154") _
From Elemento In xe.Elements("Line").Descendants _
Select Elemento.Value).ToList
If query.Any() Then
For Each Elemento In query
MsgBox(Elemento)
Next
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER