LINQ to query DataTable

Posted: January 13, 2011 in LINQ
Tags:

I am pretty new to LINQ & today my team mate was suggesting me to learn LINQ & write about it.Just starting with a small homework,how to query datatable using LINQ 🙂

What this snippet does is,there is a DataTable having columns Name,Age,Address etc,LINQ queries the table with name as input & returns Age & Address

string searchname="Anupama";
DataTable dtContacts = new DataTable();
dtContacts = this.GetContactDetails;

var query = from r in this.dtContacts.AsEnumerable()
where r.Field("Name") == searchname
select new{ Age=r["Age"],Address=r["Address"]};

Simple right?Keep Watching this space,I will get back with complicated one’s 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s