How to handle CopyToDataTable() when no rows?

后端 未结 6 1929
滥情空心
滥情空心 2020-12-15 03:21

I have the code:

dt = collListItems.GetDataTable().AsEnumerable()
        .Where(a => Convert.ToString(a[\"Expertise\"]).Contains(expertise) && Co         


        
6条回答
  •  我在风中等你
    2020-12-15 03:56

    How about this solution :

                DataRow[] filtered_rows = data.Tables[0].Select(filter_string);
    
                if(filtered_rows.Length > 0)
                {
                    filtered_data = filtered_rows.CopyToDataTable();
                }
                else
                {
                    filtered_data.Clear();
                }
    

    data.Tables[0] is the source table and filtered_data is the resultant table.

提交回复
热议问题