Linq查询到C#控制台中的Datable

0 c# linq console

var query = from r in dataTable.AsEnumerable()
                where (r.Field<double?>(dataTable.Columns[0]).Equals(invoiceNo))
                select new
                        {
                            invoice = r.Field<double>(dataTable.Columns[0]),
                            name = r.Field<string>(dataTable.Columns[1]),
                            emp_id = r.Field<double>(dataTable.Columns[2]),
                            won = r.Field<double>(dataTable.Columns[3]),
                            expenses = r.Field<double>(dataTable.Columns[4]),
                        };
Run Code Online (Sandbox Code Playgroud)

这是我的linq查询,它从dataTable中读取所有数据.

 I want the query to be converted again into a datatable.Is it possible?
Run Code Online (Sandbox Code Playgroud)

cuo*_*gle 5

你可以使用方法CopyToDataTable:

 DataTable dt = (from r in dataTable.AsEnumerable()
                where (r.Field<double?>(dataTable.Columns[0]).Equals(invoiceNo)))
             .CopyToDataTable();
Run Code Online (Sandbox Code Playgroud)