Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 27th, 2012  |  syntax: None  |  size: 0.83 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Linq to XML: .Net Windows Forms, XML query
  2. private void cboCustomer_SelectedIndexChanged(object sender, EventArgs e)
  3.     {
  4.         var doc = XElement.Load("Portfolio.xml");
  5.         customerId = cboCustomer.SelectedIndex.ToString();
  6.         if (cboCustomer.SelectedIndex != 0)
  7.         {
  8.             var custRecord =
  9.                 from account in doc.Descendants("account")
  10.                 let acct = account.Element("acct")
  11.                 where (string)account.Element("custid") == customerId
  12.                 select new
  13.                 {Fname=(string)account.Element("fname"),
  14.                     Lname = (string)account.Element("lname"),
  15.                     Ssn = (string)account.Element("ssn"),
  16.                     Dob = (string)account.Element("dob")
  17.                 };
  18.         }
  19.     }
  20.        
  21. where acct.Attribute("custid").Value == customerId