DataTableExtensions.CopyToDataTable Yöntem
Tanım
Bir DataTable DataRow giriş nesnesi verilen nesnelerin kopyalarını içeren bir döndürür IEnumerable<T> .Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object.
Aşırı Yüklemeler
CopyToDataTable<T>(IEnumerable<T>) |
DataTable DataRow Genel parametrenin bulunduğu bir giriş nesnesi verildiğinde, nesnelerin kopyalarını içeren bir döndürür IEnumerable<T> |
CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) |
DataRowNesneleri DataTable , IEnumerable<T> genel parametresinin bulunduğu bir giriş nesnesi verildiğinde, belirtilen öğesine kopyalar |
CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) |
DataRowNesneleri DataTable , IEnumerable<T> genel parametresinin bulunduğu bir giriş nesnesi verildiğinde, belirtilen öğesine kopyalar |
CopyToDataTable<T>(IEnumerable<T>)
DataTable DataRow Genel parametrenin bulunduğu bir giriş nesnesi verildiğinde, nesnelerin kopyalarını içeren bir döndürür IEnumerable<T> T
DataRow .Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T
is DataRow.
public:
generic <typename T>
where T : System::Data::DataRow[System::Runtime::CompilerServices::Extension]
static System::Data::DataTable ^ CopyToDataTable(System::Collections::Generic::IEnumerable<T> ^ source);
public static System.Data.DataTable CopyToDataTable<T> (this System.Collections.Generic.IEnumerable<T> source) where T : System.Data.DataRow;
static member CopyToDataTable : seq<'T (requires 'T :> System.Data.DataRow)> -> System.Data.DataTable (requires 'T :> System.Data.DataRow)
<Extension()>
Public Function CopyToDataTable(Of T As DataRow) (source As IEnumerable(Of T)) As DataTable
Tür Parametreleri
- T
Kaynak dizideki nesnelerin türü, genellikle DataRow .The type of objects in the source sequence, typically DataRow.
Parametreler
- source
- IEnumerable<T>
Kaynak IEnumerable<T> sırası.The source IEnumerable<T> sequence.
Döndürülenler
DataTableNesne türü olarak giriş dizisini içeren bir DataRow .A DataTable that contains the input sequence as the type of DataRow objects.
Özel durumlar
Kaynak IEnumerable<T> sırası null
ve yeni bir tablo oluşturulamıyor.The source IEnumerable<T> sequence is null
and a new table cannot be created.
DataRowKaynak dizideki bir öğesinin durumu vardır Deleted .A DataRow in the source sequence has a state of Deleted.
Kaynak sırası herhangi bir DataRow nesne içermiyor.The source sequence does not contain any DataRow objects.
DataRowKaynak dizideki A null
.A DataRow in the source sequence is null
.
Örnekler
Aşağıdaki örnek, 5 Ağustos 2001 ' den sonraki siparişler için SalesOrderHeader tablosunu sorgular ve CopyToDataTable Bu sorgudan bir oluşturmak için yöntemini kullanır DataTable .The following example queries the SalesOrderHeader table for orders after August 8, 2001, and uses the CopyToDataTable method to create a DataTable from that query. DataTableDaha sonra bir BindingSource için proxy görevi gören bir öğesine bağlanır DataGridView .The DataTable is then bound to a BindingSource, which acts as proxy for a DataGridView.
// Bind the System.Windows.Forms.DataGridView object
// to the System.Windows.Forms.BindingSource object.
dataGridView.DataSource = bindingSource;
// Fill the DataSet.
DataSet ds = new DataSet();
ds.Locale = CultureInfo.InvariantCulture;
FillDataSet(ds);
DataTable orders = ds.Tables["SalesOrderHeader"];
// Query the SalesOrderHeader table for orders placed
// after August 8, 2001.
IEnumerable<DataRow> query =
from order in orders.AsEnumerable()
where order.Field<DateTime>("OrderDate") > new DateTime(2001, 8, 1)
select order;
// Create a table from the query.
DataTable boundTable = query.CopyToDataTable<DataRow>();
// Bind the table to a System.Windows.Forms.BindingSource object,
// which acts as a proxy for a System.Windows.Forms.DataGridView object.
bindingSource.DataSource = boundTable;
' Bind the System.Windows.Forms.DataGridView object
' to the System.Windows.Forms.BindingSource object.
dataGridView.DataSource = bindingSource
' Fill the DataSet.
Dim ds As New DataSet()
ds.Locale = CultureInfo.InvariantCulture
' See the FillDataSet method in the Loading Data Into a DataSet topic.
FillDataSet(ds)
Dim orders As DataTable = ds.Tables("SalesOrderHeader")
' Query the SalesOrderHeader table for orders placed
' after August 8, 2001.
Dim query = _
From order In orders.AsEnumerable() _
Where order.Field(Of DateTime)("OrderDate") > New DateTime(2001, 8, 1) _
Select order
' Create a table from the query.
Dim boundTable As DataTable = query.CopyToDataTable()
' Bind the table to a System.Windows.Forms.BindingSource object,
' which acts as a proxy for a System.Windows.Forms.DataGridView object.
bindingSource.DataSource = boundTable
Açıklamalar
T
Giriş parametresinin parametresi source
yalnızca türü DataRow veya öğesinden türetilmiş bir tür olabilir DataRow .The parameter T
of the input parameter source
can only be of type DataRow or a type derived from DataRow.
Giriş dizisi IEnumerable<T> yalnızca bir sorgu veya bir üzerinde sorgu değil herhangi bir kaynak olabilir DataTable .The input sequence can be any IEnumerable<T> source, not only a query or a query over a DataTable. Kaynak sırası bir sorgu ise, bu işleci çağırmak hemen yürütmeye zorlayacaktır.Note that if the source sequence is a query, calling this operator will force immediate execution. Kaynak dizisinin numaralandırılması, özel durumların oluşturulmasına neden olabilir.Enumerating the source sequence can also cause exceptions to be thrown.
Hedef tablonun şeması, kaynak dizideki ilk satırın şemasını temel alır DataRow .The schema of the destination table is based on the schema of the first DataRow row in the source sequence. Tablo meta verileri DataRow , ' nin sütun değerlerinden meta verilerden ve tablo değerlerinden ayıklanır DataRow .The table metadata is extracted from the DataRow metadata and the table values from the column values of the DataRow. Türü belirlenmiş bir DataTable tür için, türler korunmaz.For a typed DataTable, types are not preserved. Veri ve şema aktarılır, ancak çıkış tablosunun sonuç satırları türü belirtilmiş DataRow türde olmayacaktır.The data and schema are transferred, but the resulting rows of the output table will not be of the typed DataRow type. RowStateVe RowError özellikleri kaynaktan döndürülen kopyalama sırasında korunmaz DataRow DataTable .The RowState and RowError properties are not preserved during the copy from the source DataRow to the returned DataTable.
Bir kaynakta null veya null değere sahip null atanabilir tür bulunursa DataRow , bu yöntem hedefteki değeri DataTable değeri ile değiştirir Value .When a null reference or nullable type with a value of null is found in a source DataRow, this method replaces the value in the destination DataTable with a value of Value.
Yöntemi tarafından döndürülen oluşturulan tablo, varsayılan tablo adına sahiptir.The generated table returned by the method has the default table name. Adını adlandırmak DataTable , bir öğesine eklemek DataSet veya başka herhangi bir işlemi gerçekleştirmek istiyorsanız, DataTable tablo oluşturulup döndürülmeden sonra bunu yapmanız gerekir.If you want to name the DataTable, attach it to a DataSet, or perform any other DataTable specific operation, you must do so after the table is created and returned.
Daha fazla bilgi için bkz. sorgudan DataTable oluşturma.For more information, see Creating a DataTable From a Query.
Şunlara uygulanır
CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)
DataRowNesneleri DataTable , IEnumerable<T> genel parametresinin bulunduğu bir giriş nesnesi verildiğinde, belirtilen öğesine kopyalar T
DataRow .Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T
is DataRow.
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);
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;
static member CopyToDataTable : seq<'T (requires 'T :> System.Data.DataRow)> * System.Data.DataTable * System.Data.LoadOption -> unit (requires 'T :> System.Data.DataRow)
<Extension()>
Public Sub CopyToDataTable(Of T As DataRow) (source As IEnumerable(Of T), table As DataTable, options As LoadOption)
Tür Parametreleri
- T
Kaynak dizideki nesnelerin türü, genellikle DataRow .The type of objects in the source sequence, typically DataRow.
Parametreler
- source
- IEnumerable<T>
Kaynak IEnumerable<T> sırası.The source IEnumerable<T> sequence.
- options
- LoadOption
LoadOptionYükleme seçeneklerini belirten bir sabit listesi DataTable .A LoadOption enumeration that specifies the DataTable load options.
Özel durumlar
Kopyalanmış DataRow nesneler hedefin şemasına uymuyor DataTable .The copied DataRow objects do not fit the schema of the destination DataTable.
Kaynak IEnumerable<T> sırası null
veya hedef DataTable null
.The source IEnumerable<T> sequence is null
or the destination DataTable is null
.
DataRowKaynak dizideki bir öğesinin durumu vardır Deleted .A DataRow in the source sequence has a state of Deleted.
Kaynak sırası herhangi bir DataRow nesne içermiyor.The source sequence does not contain any DataRow objects.
DataRowKaynak dizideki A null
.A DataRow in the source sequence is null
.
Açıklamalar
T
Giriş parametresinin parametresi source
yalnızca tür DataRow veya öğesinden türetilmiş bir tür olabilir DataRow .The parameter T
of the input parameter source
can only be of type DataRow, or a type derived from DataRow.
Giriş dizisi IEnumerable<T> yalnızca bir üzerinde sorgu değil herhangi bir kaynak olabilir DataTable .The input sequence can be any IEnumerable<T> source, not only a query over a DataTable. Kaynak sırası bir sorgu ise, bu işleci çağırmak hemen yürütmeye zorlayacaktır.Note that if the source sequence is a query, calling this operator will force immediate execution. Kaynak dizisinin numaralandırılması, özel durumların oluşturulmasına neden olabilir.Enumerating the source sequence can also cause exceptions to be thrown.
Hedef tablonun şeması, kaynak dizideki ilk satırın şemasını temel alır DataRow .The schema of the destination table is based on the schema of the first DataRow row in the source sequence. Tablo meta verileri DataRow , ' nin sütun değerlerinden meta verilerden ve tablo değerlerinden ayıklanır DataRow .The table metadata is extracted from the DataRow metadata and the table values from the column values of the DataRow. Türü belirlenmiş bir DataTable tür için, türler korunmaz.For a typed DataTable, types are not preserved. Veri ve şema aktarılır, ancak çıkış tablosunun sonuç satırları türü belirtilmiş DataRow türde olmayacaktır.The data and schema are transferred, but the resulting rows of the output table will not be of the typed DataRow type. RowStateVe RowError özellikleri kaynaktan döndürülen kopyalama sırasında korunmaz DataRow DataTable .The RowState and RowError properties are not preserved during the copy from the source DataRow to the returned DataTable.
Bir kaynakta null veya null değere sahip null atanabilir tür bulunursa DataRow , bu yöntem hedefteki değeri DataTable değeri ile değiştirir Value .When a null reference or nullable type with a value of null is found in a source DataRow, this method replaces the value in the destination DataTable with a value of Value.
Yöntemi tarafından döndürülen oluşturulan tablo, varsayılan tablo adına sahiptir.The generated table returned by the method has the default table name. Adını adlandırmak DataTable , bir öğesine eklemek DataSet veya başka herhangi bir işlemi gerçekleştirmek istiyorsanız, DataTable tablo oluşturulup döndürülmeden sonra bunu yapmanız gerekir.If you want to name the DataTable, attach it to a DataSet, or perform any other DataTable specific operation, you must do so after the table is created and returned.
Daha fazla bilgi için bkz. sorgudan DataTable oluşturma.For more information, see Creating a DataTable From a Query.
Şunlara uygulanır
CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)
DataRowNesneleri DataTable , IEnumerable<T> genel parametresinin bulunduğu bir giriş nesnesi verildiğinde, belirtilen öğesine kopyalar T
DataRow .Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T
is DataRow.
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);
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;
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;
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)
<Extension()>
Public Sub CopyToDataTable(Of T As DataRow) (source As IEnumerable(Of T), table As DataTable, options As LoadOption, errorHandler As FillErrorEventHandler)
Tür Parametreleri
- T
Kaynak dizideki nesnelerin türü, genellikle DataRow .The type of objects in the source sequence, typically DataRow.
Parametreler
- source
- IEnumerable<T>
Kaynak IEnumerable<T> sırası.The source IEnumerable<T> sequence.
- options
- LoadOption
LoadOptionYükleme seçeneklerini belirten bir sabit listesi DataTable .A LoadOption enumeration that specifies the DataTable load options.
- errorHandler
- FillErrorEventHandler
Bir FillErrorEventHandler hatayı işleyecek yöntemi temsil eden bir temsilci.A FillErrorEventHandler delegate that represents the method that will handle an error.
Özel durumlar
Kopyalanmış DataRow nesneler hedefin şemasına uymuyor DataTable .The copied DataRow objects do not fit the schema of the destination DataTable.
Kaynak IEnumerable<T> sırası null
veya hedef DataTable null
.The source IEnumerable<T> sequence is null
or the destination DataTable is null
.
DataRowKaynak dizideki bir öğesinin durumu vardır Deleted .A DataRow in the source sequence has a state of Deleted.
-veya--or- Kaynak sırası herhangi bir DataRow nesne içermiyor.The source sequence does not contain any DataRow objects.
-veya--or-
DataRowKaynak dizideki A null
.A DataRow in the source sequence is null
.
Açıklamalar
T
Giriş parametresinin parametresi source
yalnızca tür DataRow veya öğesinden türetilmiş bir tür olabilir DataRow .The parameter T
of the input parameter source
can only be of type DataRow, or a type derived from DataRow.
Giriş dizisi IEnumerable<T> yalnızca bir üzerinde sorgu değil herhangi bir kaynak olabilir DataTable .The input sequence can be any IEnumerable<T> source, not only a query over a DataTable. Kaynak sırası bir sorgu ise, bu işleci çağırmak hemen yürütmeye zorlayacaktır.Note that if the source sequence is a query, calling this operator will force immediate execution. Kaynak dizisinin numaralandırılması, özel durumların oluşturulmasına neden olabilir.Enumerating the source sequence can also cause exceptions to be thrown.
Hedef tablonun şeması, kaynak dizideki ilk satırın şemasını temel alır DataRow .The schema of the destination table is based on the schema of the first DataRow row in the source sequence. Tablo meta verileri DataRow , ' nin sütun değerlerinden meta verilerden ve tablo değerlerinden ayıklanır DataRow .The table metadata is extracted from the DataRow metadata and the table values from the column values of the DataRow. Türü belirlenmiş bir DataTable tür için, türler korunmaz.For a typed DataTable, types are not preserved. Veri ve şema aktarılır, ancak çıkış tablosunun sonuç satırları türü belirtilmiş DataRow türde olmayacaktır.The data and schema are transferred, but the resulting rows of the output table will not be of the typed DataRow type. RowStateVe RowError özellikleri kaynaktan döndürülen kopyalama sırasında korunmaz DataRow DataTable .The RowState and RowError properties are not preserved during the copy from the source DataRow to the returned DataTable.
Bir kaynakta null veya null değere sahip null atanabilir tür bulunursa DataRow , bu yöntem hedefteki değeri DataTable değeri ile değiştirir Value .When a null reference or nullable type with a value of null is found in a source DataRow, this method replaces the value in the destination DataTable with a value of Value.
Yöntemi tarafından döndürülen oluşturulan tablo, varsayılan tablo adına sahiptir.The generated table returned by the method has the default table name. Adını adlandırmak DataTable , bir öğesine eklemek DataSet veya başka herhangi bir işlemi gerçekleştirmek istiyorsanız, DataTable tablo oluşturulup döndürülmeden sonra bunu yapmanız gerekir.If you want to name the DataTable, attach it to a DataSet, or perform any other DataTable specific operation, you must do so after the table is created and returned.
Bir veri satırının bir kısıtlama özel durumu gibi hedef tabloya kopyası sırasında bir özel durum oluşturulursa, errorHandler
temsilci çağırılır.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. FillErrorEventArgs errorHandler
Aşağıdaki değerlere sahip bir temsilciye geçirilir:A FillErrorEventArgs is passed to the errorHandler
delegate with the following values:
ValuesÖzelliği, kaynak verilerin bir kopyasına ayarlanır.The Values property is set to a copy of the source data.
DataTableÖzelliği hedefe ayarlanır DataTable .The DataTable property is set to the target DataTable.
ErrorsÖzelliği yakalanan özel duruma ayarlanır.The Errors property is set to the caught exception.
ContinueTemsilci çağrısı döndüğünde Özellik okundu.The Continue property is read after the delegate call returns. ContinueÖzelliği ise true
, kaynak sırası numaralandırılmasına ve veri tablosuna yüklenmeye devam eder.If the Continue property is true
, the source sequence continues to be enumerated and loaded into the data table. ContinueÖzelliği ise false
, yönteminden özgün özel durum atılır CopyToDataTable .If the Continue property is false
, the original exception is thrown from the CopyToDataTable method.
Daha fazla bilgi için bkz. sorgudan DataTable oluşturma.For more information, see Creating a DataTable From a Query.