LINQ query on a DataTable

前端 未结 23 1673
执笔经年
执笔经年 2020-11-22 01:59

I\'m trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example:

23条回答
  •  没有蜡笔的小新
    2020-11-22 02:06

    Most likely, the classes for the DataSet, DataTable and DataRow are already defined in the solution. If that's the case you won't need the DataSetExtensions reference.

    Ex. DataSet class name-> CustomSet, DataRow class name-> CustomTableRow (with defined columns: RowNo, ...)

    var result = from myRow in myDataTable.Rows.OfType()
                 where myRow.RowNo == 1
                 select myRow;
    

    Or (as I prefer)

    var result = myDataTable.Rows.OfType().Where(myRow => myRow.RowNo);
    

提交回复
热议问题