且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Linq 过滤数据表到数据表?

更新时间:2023-01-13 14:20:09

你***使用 DataTable.Select 方法,但如果你必须使用 LINQ 那么你可以尝试:

You are better of using DataTable.Select method, but if you have to use LINQ then you can try:

DataTable selectedTable = tb.AsEnumerable()
                            .Where(r => r.Field<string>("Modul") == value)
                            .CopyToDataTable();

这将基于过滤的值创建一个新的 DataTable.

This would create a new DataTable based on filtered values.

如果您使用 DataTable.Select

string expression = "Modul =" + value;
DataRow[] selectedRows = tb.Select(expression);