我有一个linq
查询,它给了我想要的输出:
var data = (from c in dtskip.AsEnumerable()
select new[] {
c.Field<string>("Suburb"), c.Field<string>("Postcode"), c.Field<string>("State"),c.Field<string>("ID"), c.Field<string>("SEARCHKEY"), c.Field<string>("RATING"), c.Field<string>("DELIVERY")
});
如何选择所有列,而不是像c.field<string>("postcode")
那样给出名称。我输出的数据仅来自数据dtskip
:
输出:
["DARWIN","0800","NT","2","DARWINNT","A","Delivery Area"]
,["ALAWA","0810","NT","5","ALAWANT","A","Delivery Area"],
["BRINKIN","0810","NT","6","BRINKINNT","A","Delivery Area"],
有没有其他方法可以使用linq
查询从数据表中删除输出。
答案 0 :(得分:1)
你试过吗
var data = (From c in dtskip
select c).AsEnumerable(); //Not sure about the AsEnumerable :s
答案 1 :(得分:1)
DataRow
包含一个ItemArray
成员,该成员将该行中的所有数据作为数组返回,缺点是它们都返回为object
但是如果所有列都相同您可以将ItemArray
投射到所需类型(在本例中为string
)
dtskip.Rows.Cast<DataRow>().Select(r => r.ItemArray.Cast<string>());
这将为您提供IEnumerable<IEnumerable<string>>
。
答案 2 :(得分:0)
你在找这样的东西吗?
var data = dtskip.AsEnumerable().
Select(x => new
{
Suburb = x.Field<string>("Suburb"),
Postcode= x.Field<string>("Postcode"),
State= x.Field<string>("State"),
Id= x.Field<string>("ID"),
Searchkey = x.Field<string>("SEARCHKEY"),
Rating = x.Field<string>("RATING"),
Delivery = x.Field<string>("DELIVERY")
});