0
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]),
                        };

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

 I want the query to be converted again into a datatable.Is it possible?
4

2 回答 2

5

您可以使用方法CopyToDataTable

 DataTable dt = (from r in dataTable.AsEnumerable()
                where (r.Field<double?>(dataTable.Columns[0]).Equals(invoiceNo)))
             .CopyToDataTable();
于 2013-05-23T09:43:49.663 回答
0

您可以使用

dataTable.PrimaryKey = new DataColumn[]{_dataTable.Columns["Invoice"]};

dataTable.Rows.Find(invoiceNo)
于 2013-05-23T09:40:07.553 回答