开发者

LINQ to DataSet to get generic list from DataTable

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜