开发者

LINQ to DataSet to get generic list from DataTable

开发者 https://www.devze.com 2023-02-03 12:00 出处:网络
DataTable table = DataProvider.GetTable() var clientIds = from r in table.AsEnumerable() select r.Fi开发者_如何学JAVAeld<string>(\"CLIENT_ID\");
DataTable table = DataProvider.GetTable()

var clientIds = from r in table.AsEnumerable()
                select r.Fi开发者_如何学JAVAeld<string>("CLIENT_ID");

I want clientIds to be a List<string>. Currently it's an EnumerableRowCollection<>

What am I missing?


this may work

DataTable table = DataProvider.GetTable()

var clientIds = (from r in table.AsEnumerable()
                select r.Field<string>("CLIENT_ID")).ToList();


Here is one way to do it:

var clientIds = table.Rows.Cast<DataRow>().Select(r => r.Field<string>("CLIENT_ID").ToList();

Or, if this syntax is working but not bringing back the results as a list, you can do something like:

var clientIds = (from r in table.AsEnumerable()
                select r.Field<string>("CLIENT_ID")).ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消