【问题标题】:Extract DataRow with specific column from a DataSet view in C#从 C# 中的 DataSet 视图中提取具有特定列的 DataRow
【发布时间】:2016-05-29 17:35:40
【问题描述】:

我想从数据集中获取特定行,而不是整行,而只是从行中获取特定列 应该是这样的:

 dataRow datarow1 = myDataSet.Tables["table1"].Column["column3 
            and column4"].Select(column1='1' and column2='specificvalue');

有人可以帮助我吗?

【问题讨论】:

    标签: c# sql dataset datarow


    【解决方案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") };
    

    【讨论】:

      【解决方案2】:

      我的最佳猜测:

      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();
      

      【讨论】:

        猜你喜欢
        • 2018-11-09
        • 2010-09-30
        • 1970-01-01
        • 2018-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-22
        • 1970-01-01
        相关资源
        最近更新 更多