Understanding CopyToDataTable
Tables from databases are represented within DataSets via DataTable
objects. You can create custom tables in code using a special extension method named CopyToDataTable
, which can convert from EnumerableRowCollection (Of T)
into a new DataTable
. Imagine you want to create a subset of orders from the Orders
table and that you want to create a new table with this subset of information. The following code accomplishes this:
Dim query = (From ord In NwindDataSet.Orders Where String.IsNullOrEmpty(ord.ShipCountry) = False Select ord).CopyToDataTablequery.TableName = "FilteredOrders"NwindDataSet.Tables.Add(query)
The query retrieves only the orders where the ShipCountry ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.