Книга: C# 2008 Programmer
Saving the Result of a Query to a DataTable
Saving the Result of a Query to a DataTable
The result of a LINQ query can be saved into a DataTable
object by using the CopyToDataTable()
method. The CopyToDataTable()
method takes the result of a query and copies the data into a DataTable
, which can then be used for data binding.
The following example shows a LINQ query using typed DataSet with the result copied to a DataTable
object and then bound to a DataGridView control:
var query1 =
from customer in ds.Customers
where customer.Country == "USA"
select customer;
DataTable USACustomers = query1.CopyToDataTable();
dataGridView1.DataSource = USACustomers;
Note that the CopyToDataTable()
method only operates on an IEnumerable<T>
source where the generic parameter T
is of type DataRow
. Hence, it does not work for queries that project anonymous types or queries that perform table joins.
- The API
- 4.4.4 The Dispatcher
- 19.1.1. Функция jQuery()
- About the author
- Chapter 7. The state machine
- Chapter 8. Saving and restoring large rule-sets
- Appendix E. Other resources and links
- Example NAT machine in theory
- The final stage of our NAT machine
- Compiling the user-land applications
- The conntrack entries
- Untracked connections and the raw table