我想从数据集中获取特定行,而不是整行,而只是行中的特定列 它应该是这样的:
dataRow datarow1 = myDataSet.Tables["table1"].Column["column3
and column4"].Select(column1='1' and column2='specificvalue');
有人可以帮帮我吗?
答案 0 :(得分:1)
我最好的猜测:
var datarows = myDataSet.Tables["table1"].AsEnumerable()
.Where(x=> x.Field<int>("col1") == 1 && x.Field<string>("col2") == "specificvalue")
.Select(x=>new
{
col3 = x.Field<int>("col3"),
col4 = x.Field<int>("col4")
})
.ToList();
答案 1 :(得分:1)
语法略有不同:
var result = from row in set.Tables["table1"].AsEnumerable()
where row.Field<int>("column1") == 1 &&
row.Field<string>("column2") == "specificValue"
select new { Column3 = row.Field<string>("Column3"),
Column4 = row.Field<string>("Column4") };