Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataTableExtensions::AsEnumerable Method (DataTable^)

 

Returns an IEnumerable<T> object, where the generic parameter T is DataRow. This object can be used in a LINQ expression or method query.

Namespace:   System.Data
Assembly:  System.Data.DataSetExtensions (in System.Data.DataSetExtensions.dll)

public:
[ExtensionAttribute]
static EnumerableRowCollection<DataRow^>^ AsEnumerable(
	DataTable^ source
)

Parameters

source
Type: System.Data::DataTable^

The source DataTable to make enumerable.

Return Value

Type: System.Data::EnumerableRowCollection<DataRow^>^

An IEnumerable<T> object, where the generic parameter T is DataRow.

Exception Condition
ArgumentNullException

The source DataTable is null.

Language-Integrated Query (LINQ) queries work on data sources that implement the IEnumerable<T> interface or the T:System.Query.IQueryable`1 interface. The DataTable class does not implement either interface, so you must call the AsEnumerable method to use the DataTable as a source in the From clause of a LINQ query. You can also obtain custom, domain-specific operators, such as CopyToDataTable, by returning an IEnumerable<T> object. 

The enumerable object returned by the AsEnumerable method is permanently bound to the DataTable that produced it. Multiple calls to the AsEnumerable method will return multiple, independent queryable objects that are all bound to the source DataTable.

In the following sample, the DisplayProducts method receives a DataTable that contains a DataColumn named ProductName, extracts the ProductName values and then prints the values.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top
Show:
© 2017 Microsoft