How I can filter a dataTable with Linq to datatable?

前端 未结 3 1566
执念已碎
执念已碎 2020-12-14 02:59

hi how i can filter a datatable with linq to datatable? I have a DropDownList and there I can select the value of the Modul Column. Now I want to filter the DataTable with

3条回答
  •  一个人的身影
    2020-12-14 03:14

    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("Modul") == value)
                                .CopyToDataTable();
    

    This would create a new DataTable based on filtered values.

    If you use DataTable.Select

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

提交回复
热议问题