Read from XML using LINQ and bind the result to DataGridView


You can use the attached code to read from xml using LINQ and then bind the data to a datagridview in a windows form application.

Hi friends,
Here is a small project which shows a easiest way of retrieving data from a XML file using LINQ. For people who are new to LINQ please visit this link:
http://msdn.microsoft.com/library/bb308959.aspx

Please download the attached zip file. This is a small project which implement this approach. I am using LINQ to read from XML, then filtering the data and rendering it in a grid.

  
///
/// Search by the location.
///

/// The emp location.
private void SearchbyLocation(string empLocation)
{
var employees = from c in XElement.Load(@"D:\Learnings\WindowsFormsApplication1\WindowsFormsApplication1\EmployeeDB.xml").Elements("Employee")
where c.Element("Location").Value.Equals(empLocation.ToLower())
select new
{
ID = c.Element("ID").Value,
Name = c.Element("Name").Value,
Location = c.Element("Location").Value
};

dataGridView1.DataSource = employees.ToList();
}


Thanks,
Anil.


Attachments

  • Read from XML using LINQ and bind the result to DataGridView (40889-12634-WindowsFormsApplication1.zip)
  • Comments

    Guest Author: Martin11 Jun 2012

    Yes, I think you are fine applying for entry level programmer positions.What I see for programming positions right now are a lot of Microsoft .NET, C#, MS SQL Server stuff. Also Java is a good thing to know, but in my opinion, its harder to find an entry level position in Java. My advice is to load up on Microsoft technology up front, and be willing to take any programming job, anywhere, for any amount. After a year or 2 of good experience, you can start getting pickier about your development environment, pay, location, etc.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: