使用linq在数据表中选择所需的列 [英] selecting needed column in data table with linq
本文介绍了使用linq在数据表中选择所需的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据表中有很多列.
但是我需要三列.
我想知道如何用linq编写以仅获取所需的列.
There are many columns in data table .
But i want to need three column .
I want to know how to write to get only needed column with linq .
推荐答案
使用此
Use this
var selectedColumn =dtDataTable.AsEnumerable().Select(s=>s.Field<string>("ColumnName"));
尝试一下....
Try this....
var selectedColumn = from m in MyTable
where ....
select new
{
m.firstColumn,
m.secondColumn,
m.thirdColumn
};
只需在选择新{}"中写入所需的列即可.....
Just write as many columns you want inside "select new {}".....
这篇关于使用linq在数据表中选择所需的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文