-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
DataTableExtensions.xml
545 lines (477 loc) · 42.3 KB
/
DataTableExtensions.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<Type Name="DataTableExtensions" FullName="System.Data.DataTableExtensions">
<TypeSignature Language="C#" Value="public static class DataTableExtensions" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract sealed beforefieldinit DataTableExtensions extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Data.DataTableExtensions" />
<TypeSignature Language="VB.NET" Value="Public Module DataTableExtensions" />
<TypeSignature Language="F#" Value="type DataTableExtensions = class" />
<TypeSignature Language="C++ CLI" Value="public ref class DataTableExtensions abstract sealed" />
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Data.Common" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="System.Data.DataSetExtensions" FromVersion="4.0.0.0" To="System.Data.Common" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Data.Common" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="System.Data.DataSetExtensions" FromVersion="4.0.0.0" To="System.Data.Common" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Data.Common" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="System.Data.DataSetExtensions" FromVersion="4.0.0.0" To="System.Data.Common" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Data.Common" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="System.Data.DataSetExtensions" FromVersion="8.0.0.0" To="System.Data.Common" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Data.Common" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
<TypeForwarding From="System.Data.DataSetExtensions" FromVersion="9.0.0.0" To="System.Data.Common" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
<TypeForwarding From="System.Data.DataSetExtensions" FromVersion="4.0.0.0" To="System.Data.Common" ToVersion="4.2.1.0" FrameworkAlternate="netcore-3.0" />
<TypeForwarding From="System.Data.DataSetExtensions" FromVersion="4.0.1.0" To="System.Data.Common" ToVersion="4.2.2.0" FrameworkAlternate="netcore-3.1" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(1)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Defines the extension methods to the <see cref="T:System.Data.DataTable" /> class. <see cref="T:System.Data.DataTableExtensions" /> is a static class.</summary>
<remarks>To be added.</remarks>
</Docs>
<Members>
<Member MemberName="AsDataView">
<MemberSignature Language="C#" Value="public static System.Data.DataView AsDataView (this System.Data.DataTable table);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Data.DataView AsDataView(class System.Data.DataTable table) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.DataTableExtensions.AsDataView(System.Data.DataTable)" />
<MemberSignature Language="VB.NET" Value="<Extension()>
Public Function AsDataView (table As DataTable) As DataView" />
<MemberSignature Language="F#" Value="static member AsDataView : System.Data.DataTable -> System.Data.DataView" Usage="System.Data.DataTableExtensions.AsDataView table" />
<MemberSignature Language="C++ CLI" Value="public:
[System::Runtime::CompilerServices::Extension]
 static System::Data::DataView ^ AsDataView(System::Data::DataTable ^ table);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.DataView</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="table" Type="System.Data.DataTable" RefType="this" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.1" />
</Parameters>
<Docs>
<param name="table">The source <see cref="T:System.Data.DataTable" /> from which the LINQ-enabled <see cref="T:System.Data.DataView" /> is created.</param>
<summary>Creates and returns a LINQ-enabled <see cref="T:System.Data.DataView" /> object.</summary>
<returns>A LINQ-enabled <see cref="T:System.Data.DataView" /> object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Data.DataView> enables data-binding scenarios for LINQ to DataSet and can be created from a typed or untyped <xref:System.Data.DataTable>, providing a default view of that table. Filtering and sorting can be set on the <xref:System.Data.DataView> after it has been created from a <xref:System.Data.DataTable>. The <xref:System.Data.DataView> is then bound to a UI control, such as a <xref:System.Windows.Forms.DataGrid> or a <xref:System.Windows.Forms.DataGridView>, providing a simple data binding model.
For more information and examples, see [Creating a DataView Object](/dotnet/framework/data/adonet/creating-a-dataview-object-linq-to-dataset).
## Examples
The following example creates a <xref:System.Data.DataView> from the SalesOrderDetail table and sets it as the data source of a <xref:System.Windows.Forms.BindingSource> object, which acts as a proxy for a <xref:System.Windows.Forms.DataGridView> control:
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/DP DataView Samples/CS/Form1.cs" id="Snippetcreateldvfromtable":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_ADO.NET/DP DataView Samples/VB/Form1.vb" id="Snippetcreateldvfromtable":::
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AsDataView<T>">
<MemberSignature Language="C#" Value="public static System.Data.DataView AsDataView<T> (this System.Data.EnumerableRowCollection<T> source) where T : System.Data.DataRow;" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Data.DataView AsDataView<(class System.Data.DataRow) T>(class System.Data.EnumerableRowCollection`1<!!T> source) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.DataTableExtensions.AsDataView``1(System.Data.EnumerableRowCollection{``0})" />
<MemberSignature Language="VB.NET" Value="<Extension()>
Public Function AsDataView(Of T As DataRow) (source As EnumerableRowCollection(Of T)) As DataView" />
<MemberSignature Language="F#" Value="static member AsDataView : System.Data.EnumerableRowCollection<'T (requires 'T :> System.Data.DataRow)> -> System.Data.DataView (requires 'T :> System.Data.DataRow)" Usage="System.Data.DataTableExtensions.AsDataView source" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 where T : System::Data::DataRow[System::Runtime::CompilerServices::Extension]
 static System::Data::DataView ^ AsDataView(System::Data::EnumerableRowCollection<T> ^ source);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.DataView</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<BaseTypeName>System.Data.DataRow</BaseTypeName>
</Constraints>
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="System.Data.EnumerableRowCollection<T>" RefType="this" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.1" />
</Parameters>
<Docs>
<typeparam name="T">The type of objects in the source sequence, typically <see cref="T:System.Data.DataRow" />.</typeparam>
<param name="source">The source LINQ to DataSet query from which the LINQ-enabled <see cref="T:System.Data.DataView" /> is created.</param>
<summary>Creates and returns a LINQ-enabled <see cref="T:System.Data.DataView" /> object representing the LINQ to DataSet query.</summary>
<returns>A LINQ-enabled <see cref="T:System.Data.DataView" /> object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Data.DataView> enables data binding scenarios for LINQ to DataSet and can be created from a LINQ to DataSet query. The <xref:System.Data.DataView> represents the query itself, and is not a view on top of the query. The newly created <xref:System.Data.DataView> infers the filtering and sorting information from the query it is created from. The <xref:System.Data.DataView> is then bound to a UI control, such as a <xref:System.Windows.Forms.DataGrid> or a <xref:System.Windows.Forms.DataGridView>, providing a simple data-binding model.
The parameter `T` of the input parameter `source` can only be of type <xref:System.Data.DataRow> or a type derived from <xref:System.Data.DataRow>.
The following query operators, only, are supported in a query used to create <xref:System.Data.DataView>:
- <xref:System.Data.EnumerableRowCollectionExtensions.Cast%2A>
- <xref:System.Data.EnumerableRowCollectionExtensions.OrderBy%2A>
- <xref:System.Data.EnumerableRowCollectionExtensions.OrderByDescending%2A>
- <xref:System.Data.EnumerableRowCollectionExtensions.Select%2A>
- <xref:System.Data.EnumerableRowCollectionExtensions.ThenBy%2A>
- <xref:System.Data.EnumerableRowCollectionExtensions.ThenByDescending%2A>
- <xref:System.Data.EnumerableRowCollectionExtensions.Where%2A>
For more information and examples, see [Creating a DataView Object](/dotnet/framework/data/adonet/creating-a-dataview-object-linq-to-dataset).
## Examples
The following example creates a <xref:System.Data.DataView> of online orders ordered by total due:
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/DP DataView Samples/CS/Form1.cs" id="Snippetcreateldvfromquery1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_ADO.NET/DP DataView Samples/VB/Form1.vb" id="Snippetcreateldvfromquery1":::
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AsEnumerable">
<MemberSignature Language="C#" Value="public static System.Data.EnumerableRowCollection<System.Data.DataRow> AsEnumerable (this System.Data.DataTable source);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Data.EnumerableRowCollection`1<class System.Data.DataRow> AsEnumerable(class System.Data.DataTable source) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.DataTableExtensions.AsEnumerable(System.Data.DataTable)" />
<MemberSignature Language="VB.NET" Value="<Extension()>
Public Function AsEnumerable (source As DataTable) As EnumerableRowCollection(Of DataRow)" />
<MemberSignature Language="F#" Value="static member AsEnumerable : System.Data.DataTable -> System.Data.EnumerableRowCollection<System.Data.DataRow>" Usage="System.Data.DataTableExtensions.AsEnumerable source" />
<MemberSignature Language="C++ CLI" Value="public:
[System::Runtime::CompilerServices::Extension]
 static System::Data::EnumerableRowCollection<System::Data::DataRow ^> ^ AsEnumerable(System::Data::DataTable ^ source);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.EnumerableRowCollection<System.Data.DataRow></ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="source" Type="System.Data.DataTable" RefType="this" />
</Parameters>
<Docs>
<param name="source">The source <see cref="T:System.Data.DataTable" /> to make enumerable.</param>
<summary>Returns an <see cref="T:System.Collections.Generic.IEnumerable`1" /> object, where the generic parameter <paramref name="T" /> is <see cref="T:System.Data.DataRow" />. This object can be used in a LINQ expression or method query.</summary>
<returns>An <see cref="T:System.Collections.Generic.IEnumerable`1" /> object, where the generic parameter <paramref name="T" /> is <see cref="T:System.Data.DataRow" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Language-Integrated Query (LINQ) queries work on data sources that implement the <xref:System.Collections.Generic.IEnumerable%601> interface or the <xref:System.Linq.IQueryable> interface. The <xref:System.Data.DataTable> class does not implement either interface, so you must call the <xref:System.Data.DataTableExtensions.AsEnumerable%2A> method to use the <xref:System.Data.DataTable> as a source in the `From` clause of a LINQ query. You can also obtain custom, domain-specific operators, such as <xref:System.Data.DataTableExtensions.CopyToDataTable%2A>, by returning an <xref:System.Collections.Generic.IEnumerable%601> object.
The enumerable object returned by the <xref:System.Data.DataTableExtensions.AsEnumerable%2A> method is permanently bound to the <xref:System.Data.DataTable> that produced it. Multiple calls to the <xref:System.Data.DataTableExtensions.AsEnumerable%2A> method will return multiple, independent queryable objects that are all bound to the source <xref:System.Data.DataTable>.
## Examples
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.
:::code language="csharp" source="~/snippets/csharp/System.Data/DataTableExtensions/AsEnumerable/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.data.datatableextensions.asenumerable/vb/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The source <see cref="T:System.Data.DataTable" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<MemberGroup MemberName="CopyToDataTable<T>">
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Returns a <see cref="T:System.Data.DataTable" /> that contains copies of the <see cref="T:System.Data.DataRow" /> objects, given an input <see cref="T:System.Collections.Generic.IEnumerable`1" /> object.</summary>
</Docs>
</MemberGroup>
<Member MemberName="CopyToDataTable<T>">
<MemberSignature Language="C#" Value="public static System.Data.DataTable CopyToDataTable<T> (this System.Collections.Generic.IEnumerable<T> source) where T : System.Data.DataRow;" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Data.DataTable CopyToDataTable<(class System.Data.DataRow) T>(class System.Collections.Generic.IEnumerable`1<!!T> source) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.DataTableExtensions.CopyToDataTable``1(System.Collections.Generic.IEnumerable{``0})" />
<MemberSignature Language="VB.NET" Value="<Extension()>
Public Function CopyToDataTable(Of T As DataRow) (source As IEnumerable(Of T)) As DataTable" />
<MemberSignature Language="F#" Value="static member CopyToDataTable : seq<'T (requires 'T :> System.Data.DataRow)> -> System.Data.DataTable (requires 'T :> System.Data.DataRow)" Usage="System.Data.DataTableExtensions.CopyToDataTable source" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 where T : System::Data::DataRow[System::Runtime::CompilerServices::Extension]
 static System::Data::DataTable ^ CopyToDataTable(System::Collections::Generic::IEnumerable<T> ^ source);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.DataTable</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<BaseTypeName>System.Data.DataRow</BaseTypeName>
</Constraints>
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="System.Collections.Generic.IEnumerable<T>" RefType="this" />
</Parameters>
<Docs>
<typeparam name="T">The type of objects in the source sequence, typically <see cref="T:System.Data.DataRow" />.</typeparam>
<param name="source">The source <see cref="T:System.Collections.Generic.IEnumerable`1" /> sequence.</param>
<summary>Returns a <see cref="T:System.Data.DataTable" /> that contains copies of the <see cref="T:System.Data.DataRow" /> objects, given an input <see cref="T:System.Collections.Generic.IEnumerable`1" /> object where the generic parameter <paramref name="T" /> is <see cref="T:System.Data.DataRow" />.</summary>
<returns>A <see cref="T:System.Data.DataTable" /> that contains the input sequence as the type of <see cref="T:System.Data.DataRow" /> objects.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The parameter `T` of the input parameter `source` can only be of type <xref:System.Data.DataRow> or a type derived from <xref:System.Data.DataRow>.
The input sequence can be any <xref:System.Collections.Generic.IEnumerable%601> source, not only a query or a query over a <xref:System.Data.DataTable>. Note that if the source sequence is a query, calling this operator will force immediate execution. Enumerating the source sequence can also cause exceptions to be thrown.
The schema of the destination table is based on the schema of the first <xref:System.Data.DataRow> row in the source sequence. The table metadata is extracted from the <xref:System.Data.DataRow> metadata and the table values from the column values of the <xref:System.Data.DataRow>. For a typed <xref:System.Data.DataTable>, types are not preserved. The data and schema are transferred, but the resulting rows of the output table will not be of the typed <xref:System.Data.DataRow> type. The <xref:System.Data.DataRow.RowState%2A> and <xref:System.Data.DataRow.RowError%2A> properties are not preserved during the copy from the source <xref:System.Data.DataRow> to the returned <xref:System.Data.DataTable>.
When a **null** reference or nullable type with a value of **null** is found in a source <xref:System.Data.DataRow>, this method replaces the value in the destination <xref:System.Data.DataTable> with a value of <xref:System.DBNull.Value>.
The generated table returned by the method has the default table name. If you want to name the <xref:System.Data.DataTable>, attach it to a <xref:System.Data.DataSet>, or perform any other <xref:System.Data.DataTable> specific operation, you must do so after the table is created and returned.
For more information, see [Creating a DataTable From a Query](/dotnet/framework/data/adonet/creating-a-datatable-from-a-query-linq-to-dataset).
## Examples
The following example queries the SalesOrderHeader table for orders after August 8, 2001, and uses the <xref:System.Data.DataTableExtensions.CopyToDataTable%2A> method to create a <xref:System.Data.DataTable> from that query. The <xref:System.Data.DataTable> is then bound to a <xref:System.Windows.Forms.BindingSource>, which acts as proxy for a <xref:System.Windows.Forms.DataGridView>.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/DP LINQ to DataSet Examples/CS/Program.cs" id="Snippetcopytodatatable1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_ADO.NET/DP LINQ to DataSet Examples/VB/Module1.vb" id="Snippetcopytodatatable1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The source <see cref="T:System.Collections.Generic.IEnumerable`1" /> sequence is <see langword="null" /> and a new table cannot be created.</exception>
<exception cref="T:System.InvalidOperationException">A <see cref="T:System.Data.DataRow" /> in the source sequence has a state of <see cref="F:System.Data.DataRowState.Deleted" />.
The source sequence does not contain any <see cref="T:System.Data.DataRow" /> objects.
A <see cref="T:System.Data.DataRow" /> in the source sequence is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName="CopyToDataTable<T>">
<MemberSignature Language="C#" Value="public static void CopyToDataTable<T> (this System.Collections.Generic.IEnumerable<T> source, System.Data.DataTable table, System.Data.LoadOption options) where T : System.Data.DataRow;" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void CopyToDataTable<(class System.Data.DataRow) T>(class System.Collections.Generic.IEnumerable`1<!!T> source, class System.Data.DataTable table, valuetype System.Data.LoadOption options) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.DataTableExtensions.CopyToDataTable``1(System.Collections.Generic.IEnumerable{``0},System.Data.DataTable,System.Data.LoadOption)" />
<MemberSignature Language="VB.NET" Value="<Extension()>
Public Sub CopyToDataTable(Of T As DataRow) (source As IEnumerable(Of T), table As DataTable, options As LoadOption)" />
<MemberSignature Language="F#" Value="static member CopyToDataTable : seq<'T (requires 'T :> System.Data.DataRow)> * System.Data.DataTable * System.Data.LoadOption -> unit (requires 'T :> System.Data.DataRow)" Usage="System.Data.DataTableExtensions.CopyToDataTable (source, table, options)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 where T : System::Data::DataRow[System::Runtime::CompilerServices::Extension]
 static void CopyToDataTable(System::Collections::Generic::IEnumerable<T> ^ source, System::Data::DataTable ^ table, System::Data::LoadOption options);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<BaseTypeName>System.Data.DataRow</BaseTypeName>
</Constraints>
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="System.Collections.Generic.IEnumerable<T>" RefType="this" />
<Parameter Name="table" Type="System.Data.DataTable" />
<Parameter Name="options" Type="System.Data.LoadOption" />
</Parameters>
<Docs>
<typeparam name="T">The type of objects in the source sequence, typically <see cref="T:System.Data.DataRow" />.</typeparam>
<param name="source">The source <see cref="T:System.Collections.Generic.IEnumerable`1" /> sequence.</param>
<param name="table">The destination <see cref="T:System.Data.DataTable" />.</param>
<param name="options">A <see cref="T:System.Data.LoadOption" /> enumeration that specifies the <see cref="T:System.Data.DataTable" /> load options.</param>
<summary>Copies <see cref="T:System.Data.DataRow" /> objects to the specified <see cref="T:System.Data.DataTable" />, given an input <see cref="T:System.Collections.Generic.IEnumerable`1" /> object where the generic parameter <paramref name="T" /> is <see cref="T:System.Data.DataRow" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The parameter `T` of the input parameter `source` can only be of type <xref:System.Data.DataRow>, or a type derived from <xref:System.Data.DataRow>.
The input sequence can be any <xref:System.Collections.Generic.IEnumerable%601> source, not only a query over a <xref:System.Data.DataTable>. Note that if the source sequence is a query, calling this operator will force immediate execution. Enumerating the source sequence can also cause exceptions to be thrown.
The schema of the destination table is based on the schema of the first <xref:System.Data.DataRow> row in the source sequence. The table metadata is extracted from the <xref:System.Data.DataRow> metadata and the table values from the column values of the <xref:System.Data.DataRow>. For a typed <xref:System.Data.DataTable>, types are not preserved. The data and schema are transferred, but the resulting rows of the output table will not be of the typed <xref:System.Data.DataRow> type. The <xref:System.Data.DataRow.RowState%2A> and <xref:System.Data.DataRow.RowError%2A> properties are not preserved during the copy from the source <xref:System.Data.DataRow> to the returned <xref:System.Data.DataTable>.
When a **null** reference or nullable type with a value of **null** is found in a source <xref:System.Data.DataRow>, this method replaces the value in the destination <xref:System.Data.DataTable> with a value of <xref:System.DBNull.Value>.
The generated table returned by the method has the default table name. If you want to name the <xref:System.Data.DataTable>, attach it to a <xref:System.Data.DataSet>, or perform any other <xref:System.Data.DataTable> specific operation, you must do so after the table is created and returned.
For more information, see [Creating a DataTable From a Query](/dotnet/framework/data/adonet/creating-a-datatable-from-a-query-linq-to-dataset).
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The copied <see cref="T:System.Data.DataRow" /> objects do not fit the schema of the destination <see cref="T:System.Data.DataTable" />.</exception>
<exception cref="T:System.ArgumentNullException">The source <see cref="T:System.Collections.Generic.IEnumerable`1" /> sequence is <see langword="null" /> or the destination <see cref="T:System.Data.DataTable" /> is <see langword="null" />.</exception>
<exception cref="T:System.InvalidOperationException">A <see cref="T:System.Data.DataRow" /> in the source sequence has a state of <see cref="F:System.Data.DataRowState.Deleted" />.
The source sequence does not contain any <see cref="T:System.Data.DataRow" /> objects.
A <see cref="T:System.Data.DataRow" /> in the source sequence is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName="CopyToDataTable<T>">
<MemberSignature Language="C#" Value="public static void CopyToDataTable<T> (this System.Collections.Generic.IEnumerable<T> source, System.Data.DataTable table, System.Data.LoadOption options, System.Data.FillErrorEventHandler? errorHandler) where T : System.Data.DataRow;" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void CopyToDataTable<(class System.Data.DataRow) T>(class System.Collections.Generic.IEnumerable`1<!!T> source, class System.Data.DataTable table, valuetype System.Data.LoadOption options, class System.Data.FillErrorEventHandler errorHandler) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.DataTableExtensions.CopyToDataTable``1(System.Collections.Generic.IEnumerable{``0},System.Data.DataTable,System.Data.LoadOption,System.Data.FillErrorEventHandler)" />
<MemberSignature Language="VB.NET" Value="<Extension()>
Public Sub CopyToDataTable(Of T As DataRow) (source As IEnumerable(Of T), table As DataTable, options As LoadOption, errorHandler As FillErrorEventHandler)" />
<MemberSignature Language="F#" Value="static member CopyToDataTable : seq<'T (requires 'T :> System.Data.DataRow)> * System.Data.DataTable * System.Data.LoadOption * System.Data.FillErrorEventHandler -> unit (requires 'T :> System.Data.DataRow)" Usage="System.Data.DataTableExtensions.CopyToDataTable (source, table, options, errorHandler)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 where T : System::Data::DataRow[System::Runtime::CompilerServices::Extension]
 static void CopyToDataTable(System::Collections::Generic::IEnumerable<T> ^ source, System::Data::DataTable ^ table, System::Data::LoadOption options, System::Data::FillErrorEventHandler ^ errorHandler);" />
<MemberSignature Language="C#" Value="public static void CopyToDataTable<T> (this System.Collections.Generic.IEnumerable<T> source, System.Data.DataTable table, System.Data.LoadOption options, System.Data.FillErrorEventHandler errorHandler) where T : System.Data.DataRow;" FrameworkAlternate="netcore-3.0;netcore-3.1;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.DataSetExtensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<BaseTypeName>System.Data.DataRow</BaseTypeName>
</Constraints>
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="System.Collections.Generic.IEnumerable<T>" RefType="this" />
<Parameter Name="table" Type="System.Data.DataTable" />
<Parameter Name="options" Type="System.Data.LoadOption" />
<Parameter Name="errorHandler" Type="System.Data.FillErrorEventHandler">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<typeparam name="T">The type of objects in the source sequence, typically <see cref="T:System.Data.DataRow" />.</typeparam>
<param name="source">The source <see cref="T:System.Collections.Generic.IEnumerable`1" /> sequence.</param>
<param name="table">The destination <see cref="T:System.Data.DataTable" />.</param>
<param name="options">A <see cref="T:System.Data.LoadOption" /> enumeration that specifies the <see cref="T:System.Data.DataTable" /> load options.</param>
<param name="errorHandler">A <see cref="T:System.Data.FillErrorEventHandler" /> delegate that represents the method that will handle an error.</param>
<summary>Copies <see cref="T:System.Data.DataRow" /> objects to the specified <see cref="T:System.Data.DataTable" />, given an input <see cref="T:System.Collections.Generic.IEnumerable`1" /> object where the generic parameter <paramref name="T" /> is <see cref="T:System.Data.DataRow" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The parameter `T` of the input parameter `source` can only be of type <xref:System.Data.DataRow>, or a type derived from <xref:System.Data.DataRow>.
The input sequence can be any <xref:System.Collections.Generic.IEnumerable%601> source, not only a query over a <xref:System.Data.DataTable>. Note that if the source sequence is a query, calling this operator will force immediate execution. Enumerating the source sequence can also cause exceptions to be thrown.
The schema of the destination table is based on the schema of the first <xref:System.Data.DataRow> row in the source sequence. The table metadata is extracted from the <xref:System.Data.DataRow> metadata and the table values from the column values of the <xref:System.Data.DataRow>. For a typed <xref:System.Data.DataTable>, types are not preserved. The data and schema are transferred, but the resulting rows of the output table will not be of the typed <xref:System.Data.DataRow> type. The <xref:System.Data.DataRow.RowState%2A> and <xref:System.Data.DataRow.RowError%2A> properties are not preserved during the copy from the source <xref:System.Data.DataRow> to the returned <xref:System.Data.DataTable>.
When a **null** reference or nullable type with a value of **null** is found in a source <xref:System.Data.DataRow>, this method replaces the value in the destination <xref:System.Data.DataTable> with a value of <xref:System.DBNull.Value>.
The generated table returned by the method has the default table name. If you want to name the <xref:System.Data.DataTable>, attach it to a <xref:System.Data.DataSet>, or perform any other <xref:System.Data.DataTable> specific operation, you must do so after the table is created and returned.
If an exception is thrown during the copy of a data row into the target table, such as a constraint exception, the `errorHandler` delegate is called. A <xref:System.Data.FillErrorEventArgs> is passed to the `errorHandler` delegate with the following values:
- The <xref:System.Data.FillErrorEventArgs.Values%2A> property is set to a copy of the source data.
- The <xref:System.Data.FillErrorEventArgs.DataTable%2A> property is set to the target <xref:System.Data.DataTable>.
- The <xref:System.Data.FillErrorEventArgs.Errors%2A> property is set to the caught exception.
The <xref:System.Data.FillErrorEventArgs.Continue%2A> property is read after the delegate call returns. If the <xref:System.Data.FillErrorEventArgs.Continue%2A> property is `true`, the source sequence continues to be enumerated and loaded into the data table. If the <xref:System.Data.FillErrorEventArgs.Continue%2A> property is `false`, the original exception is thrown from the <xref:System.Data.DataTableExtensions.CopyToDataTable%2A> method.
For more information, see [Creating a DataTable From a Query](/dotnet/framework/data/adonet/creating-a-datatable-from-a-query-linq-to-dataset).
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The copied <see cref="T:System.Data.DataRow" /> objects do not fit the schema of the destination <see cref="T:System.Data.DataTable" />.</exception>
<exception cref="T:System.ArgumentNullException">The source <see cref="T:System.Collections.Generic.IEnumerable`1" /> sequence is <see langword="null" /> or the destination <see cref="T:System.Data.DataTable" /> is <see langword="null" />.</exception>
<exception cref="T:System.InvalidOperationException">A <see cref="T:System.Data.DataRow" /> in the source sequence has a state of <see cref="F:System.Data.DataRowState.Deleted" />.
-or-
The source sequence does not contain any <see cref="T:System.Data.DataRow" /> objects.
-or-
A <see cref="T:System.Data.DataRow" /> in the source sequence is <see langword="null" />.</exception>
</Docs>
</Member>
</Members>
</Type>