Database Reference
In-Depth Information
•
Set the Name property to txtLinqToXml.
•
Set the Multiline property to True.
•
Set the ScrollBars property to Vertical.
•
For the Size property, set Width to 340 and Height to 298.
4.
Now your LinqToXml form in the Design view should look like Figure 18-9.
Figure 18-9.
The Design view of the LinqToXml form
5.
Open the newly added form
LinqToXml.cs
in code view. Add the code shown in
Listing 18-3 in
LinqToXml.cs
.
Listing 18-3.
LinqToXml.cs
using System.Xml.Linq;
//Load the productstable.xml in memory
XElement doc = XElement.Load(@"C:\VidyaVrat\C#2012 and SQL
2012\Chapter18\Code\Linq\productstable.xml");
//Query xml doc
var products = from prodname in doc.Descendants("products")
select prodname.Value;
//Display details
foreach (var prodname in products)
{
txtLinqToXml.AppendText("Product's Detail= ");
txtLinqToXml.AppendText(prodname);
txtLinqToXml.AppendText("\n");
}