Click here to Skip to main content
12,445,274 members (57,343 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

13.7K views
2 bookmarked
Posted

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

, 18 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Which will crash if the datatype of the column is not a string.You might also want to note that this only works for typed datasets.This version works for all datasets, can handle any datatype, and handles null values: table.Rows.AsQueryable() // make...
Which will crash if the datatype of the column is not a string.
You might also want to note that this only works for typed datasets.

This version works for all datasets, can handle any datatype, and handles null values:
table.Rows.AsQueryable<datarow>()                   // make enumerable
.Select(row => (row["fieldname"] ?? "").ToString()) // get value
.ToArray();                                         // as array

License

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

Share

About the Author

Kabwla.Phone
Software Developer (Senior)
Netherlands Netherlands
Doing that 'computer thing' ever since the C64.

Sometimes I feel that being a programmer is much like being a doctor: You just have to know everything and if you don't, something dies.

Either being an appliction or a patient.
Oddly enough, more people care about the death of their application, than the massacre op people...

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralReason for my vote of 1 copy pasted Pin
B Birajdar21-Oct-11 3:32
memberB Birajdar21-Oct-11 3:32 
Generalyour last sentence is 100% correct...I faced the same proble... Pin
B Birajdar20-Oct-11 2:55
memberB Birajdar20-Oct-11 2:55 
GeneralReason for my vote of 5 Excellent alternative Pin
B Birajdar20-Oct-11 2:55
memberB Birajdar20-Oct-11 2:55 
GeneralWhy wont you come up with your own ideas ? There are thousan... Pin
B Birajdar19-Oct-11 9:26
memberB Birajdar19-Oct-11 9:26 
GeneralRe: I do not understand why you attack me. I just point out a fe... Pin
Kabwla.Phone20-Oct-11 2:02
memberKabwla.Phone20-Oct-11 2:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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.160811.3 | Last Updated 18 Oct 2011
Article Copyright 2011 by Kabwla.Phone
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid