Click here to Skip to main content
11,436,156 members (63,617 online)
Click here to Skip to main content

Tagged as

LINQ: Get all the values from a column in a DataTable in C#

, 13 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
LINQ: Get all the values from a column in a DataTable in C#
You can get the values from a named column in the DataTable using a single line of code in LINQ.

Steps:
  1. Convert the DataTable object to Enumerable().
  2. Apply the select clause with the column name as field name.
  3. Cast it to a string array.
    string[] strSummCities = dtTemp1.AsEnumerable().Select(s => s.Field<string>("City")).ToArray<string>();

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

aspnet -i
Web Developer
India India
Software developer by profession, working for a service and product based organisation in India.

Career graph:
Software Programmer since 2002.
Web Developer in ASP.NET since 2004.

Interests:
I love reading the blogs and articles of technology experts. I love codeproject and stackoverflow .

I love to share knowledge and help the programmers. I appreciate if some body corrects my code or my concepts which helps me learn.

Comments and Discussions

 
Questionany thoughts on distinct? Pin
Member 435337117-Nov-14 19:01
memberMember 435337117-Nov-14 19:01 
QuestionGetting "Specified cast is not valid" error Pin
Silas Pereira6-Dec-12 0:27
memberSilas Pereira6-Dec-12 0:27 
AnswerRe: Getting "Specified cast is not valid" error Pin
aspnet_regiis -i6-Dec-12 0:42
memberaspnet_regiis -i6-Dec-12 0:42 
GeneralReason for my vote of 1 Personally attacked because of provi... Pin
Kabwla.Phone20-Oct-11 3:03
memberKabwla.Phone20-Oct-11 3:03 
QuestionNice Pin
Matt U.14-Oct-11 3:12
memberMatt U.14-Oct-11 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150428.2 | Last Updated 13 Oct 2011
Article Copyright 2011 by aspnet -i
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid