CopyToDataTable returns
a DataTable that contains copies of the DataRow objects. The method is part of the DataTable-
Extensions class and takes an IEnumerable(Of T) object, where a parameter T is a generic
DataRow.
The following example populates DataSet with data from the SalesOrderHeader table and then queries
using a LINQ to DataSet query. The query returns an enumeration of DataRow objects that is used to populate
a DataTable via the CopyToDataTable method. Once the DataTable is populated, a new DataView
is created and populated with the DataTable. The DataView is then assigned to the DataSource property
of a DataGridView.
try
{
int salesPersonID = Convert.ToInt32(textBox3.Text);
DataSet ds = new DataSet();
string connectionInfo = "Data Source=avalonserver;Initial Catalog=AdventureWorks;
Integrated Security=true";
SqlDataAdapter da = new SqlDataAdapter(
"SELECT SalesOrderID, OrderDate, " +
"SalesOrderNumber, SalesPersonID, ContactID, TotalDue " +
"FROM sales.salesorderheader " +
"WHERE SalesPersonID = @ID; ", connectionInfo);
da.
Pages:
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451