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





1.00/5 (1 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 dataset
s.
This version works for all dataset
s, can handle any datatype
, and handles null
values:
table.Rows.AsQueryable<datarow>() // make enumerable
.Select(row => (row["fieldname"] ?? "").ToString()) // get value
.ToArray(); // as array