DataTableExtensions.CopyToDataTable 메서드

정의

지정된 입력 DataTable 개체를 사용하여 DataRow 개체의 복사본이 들어 있는 IEnumerable<T>을 반환합니다.

오버로드

CopyToDataTable<T>(IEnumerable<T>)

제네릭 매개 변수 TDataTable인 지정된 입력 DataRow 개체를 사용하여 IEnumerable<T> 개체의 복사본이 들어 있는 DataRow을 반환합니다.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

제네릭 매개 변수 TDataRow인 지정된 입력 DataTable 개체를 사용하여 IEnumerable<T> 개체를 지정된 DataRow에 복사합니다.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

제네릭 매개 변수 TDataRow인 지정된 입력 DataTable 개체를 사용하여 IEnumerable<T> 개체를 지정된 DataRow에 복사합니다.

CopyToDataTable<T>(IEnumerable<T>)

Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs

제네릭 매개 변수 TDataTable인 지정된 입력 DataRow 개체를 사용하여 IEnumerable<T> 개체의 복사본이 들어 있는 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

소스 시퀀스의 개체 형식(일반적으로 DataRow)입니다.

매개 변수

source
IEnumerable<T>

소스 IEnumerable<T> 시퀀스입니다.

반환

DataTable 개체 형식의 입력 시퀀스가 들어 있는 DataRow입니다.

예외

소스 IEnumerable<T> 시퀀스가 null이고 새 테이블을 만들 수 없는 경우

소스 시퀀스의 DataRow 상태가 Deleted인 경우

소스 시퀀스에 DataRow 개체가 없는 경우

소스 시퀀스의 DataRownull인 경우

예제

다음 예제에서는 SalesOrderHeader 테이블에서 2001년 8월 8일 이후의 주문을 쿼리하고 메서드를 CopyToDataTable 사용하여 해당 쿼리에서 를 DataTable 만듭니다. 그런 다음, DataTableDataGridView에 대한 프록시 역할을 하는 BindingSource에 바인딩됩니다.

// 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

설명

입력 매개 변수의 매개 변수 Tsource 는 형식 DataRow 이거나 에서 DataRow파생된 형식일 수 있습니다.

입력 시퀀스는 에 대한 쿼리 또는 쿼리뿐만 아니라 모든 IEnumerable<T> 원본일 수 있습니다 DataTable. 원본 시퀀스가 쿼리인 경우 이 연산자를 호출하면 즉시 실행됩니다. 소스 시퀀스를 열거하면 예외가 throw될 수도 있습니다.

대상 테이블의 스키마는 원본 시퀀스에서 첫 번째 DataRow 행의 스키마를 기반으로 합니다. 테이블 메타데이터는 의 열 값에서 DataRow 메타데이터 및 테이블 값 DataRow에서 추출됩니다. 형식화된 DataTable의 경우 형식이 유지되지 않습니다. 데이터와 스키마가 전송되지만 출력 테이블의 결과 행은 형식화된 DataRow 형식이 아닙니다. RowStateRowError 속성은 원본 DataRow 에서 반환DataTable된 로 복사하는 동안 유지되지 않습니다.

null 값이 null인 null 참조 또는 nullable 형식이 원본 DataRow에 있으면 이 메서드는 대상 DataTable 의 값을 값 Value으로 바꿉니다.

메서드에서 반환된 생성된 테이블에는 기본 테이블 이름이 있습니다. 이름을 로 DataTable지정하거나 에 연결 DataSet하거나 다른 DataTable 특정 작업을 수행하려면 테이블을 만들고 반환한 후에 수행해야 합니다.

자세한 내용은 쿼리에서 DataTable 만들기를 참조하세요.

적용 대상

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs

제네릭 매개 변수 TDataRow인 지정된 입력 DataTable 개체를 사용하여 IEnumerable<T> 개체를 지정된 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

소스 시퀀스의 개체 형식(일반적으로 DataRow)입니다.

매개 변수

source
IEnumerable<T>

소스 IEnumerable<T> 시퀀스입니다.

table
DataTable

대상 DataTable입니다.

options
LoadOption

LoadOption 로드 옵션을 지정하는 DataTable 열거형입니다.

예외

복사된 DataRow 개체가 대상 DataTable의 스키마에 맞지 않는 경우

소스 IEnumerable<T> 시퀀스가 null이거나 대상 DataTablenull인 경우

소스 시퀀스의 DataRow 상태가 Deleted인 경우

소스 시퀀스에 DataRow 개체가 없는 경우

소스 시퀀스의 DataRownull인 경우

설명

입력 매개 변수의 매개 변수 Tsource 는 형식 DataRow이거나 에서 DataRow파생된 형식일 수 있습니다.

입력 시퀀스는 에 대한 DataTable쿼리뿐만 아니라 모든 IEnumerable<T> 원본일 수 있습니다. 원본 시퀀스가 쿼리인 경우 이 연산자를 호출하면 즉시 실행됩니다. 소스 시퀀스를 열거하면 예외가 throw될 수도 있습니다.

대상 테이블의 스키마는 원본 시퀀스에서 첫 번째 DataRow 행의 스키마를 기반으로 합니다. 테이블 메타데이터는 의 열 값에서 DataRow 메타데이터 및 테이블 값 DataRow에서 추출됩니다. 형식화된 DataTable의 경우 형식이 유지되지 않습니다. 데이터와 스키마가 전송되지만 출력 테이블의 결과 행은 형식화된 DataRow 형식이 아닙니다. RowStateRowError 속성은 원본 DataRow 에서 반환DataTable된 로 복사하는 동안 유지되지 않습니다.

null 값이 null인 null 참조 또는 nullable 형식이 원본 DataRow에 있으면 이 메서드는 대상 DataTable 의 값을 값 Value으로 바꿉니다.

메서드에서 반환된 생성된 테이블에는 기본 테이블 이름이 있습니다. 이름을 로 DataTable지정하거나 에 연결 DataSet하거나 다른 DataTable 특정 작업을 수행하려면 테이블을 만들고 반환한 후에 수행해야 합니다.

자세한 내용은 쿼리에서 DataTable 만들기를 참조하세요.

적용 대상

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs

제네릭 매개 변수 TDataRow인 지정된 입력 DataTable 개체를 사용하여 IEnumerable<T> 개체를 지정된 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

소스 시퀀스의 개체 형식(일반적으로 DataRow)입니다.

매개 변수

source
IEnumerable<T>

소스 IEnumerable<T> 시퀀스입니다.

table
DataTable

대상 DataTable입니다.

options
LoadOption

LoadOption 로드 옵션을 지정하는 DataTable 열거형입니다.

errorHandler
FillErrorEventHandler

오류를 처리할 메서드를 나타내는 FillErrorEventHandler 대리자입니다.

예외

복사된 DataRow 개체가 대상 DataTable의 스키마에 맞지 않는 경우

소스 IEnumerable<T> 시퀀스가 null이거나 대상 DataTablenull인 경우

소스 시퀀스의 DataRow 상태가 Deleted인 경우

또는

소스 시퀀스에 DataRow 개체가 없는 경우

또는

소스 시퀀스의 DataRownull인 경우

설명

입력 매개 변수의 매개 변수 Tsource 는 형식 DataRow이거나 에서 DataRow파생된 형식일 수 있습니다.

입력 시퀀스는 에 대한 DataTable쿼리뿐만 아니라 모든 IEnumerable<T> 원본일 수 있습니다. 원본 시퀀스가 쿼리인 경우 이 연산자를 호출하면 즉시 실행됩니다. 소스 시퀀스를 열거하면 예외가 throw될 수도 있습니다.

대상 테이블의 스키마는 원본 시퀀스에서 첫 번째 DataRow 행의 스키마를 기반으로 합니다. 테이블 메타데이터는 의 열 값에서 DataRow 메타데이터 및 테이블 값 DataRow에서 추출됩니다. 형식화된 DataTable의 경우 형식이 유지되지 않습니다. 데이터와 스키마가 전송되지만 출력 테이블의 결과 행은 형식화된 DataRow 형식이 아닙니다. RowStateRowError 속성은 원본 DataRow 에서 반환DataTable된 로 복사하는 동안 유지되지 않습니다.

null 값이 null인 null 참조 또는 nullable 형식이 원본 DataRow에 있으면 이 메서드는 대상 DataTable 의 값을 값 Value으로 바꿉니다.

메서드에서 반환된 생성된 테이블에는 기본 테이블 이름이 있습니다. 이름을 로 DataTable지정하거나 에 연결 DataSet하거나 다른 DataTable 특정 작업을 수행하려면 테이블을 만들고 반환한 후에 수행해야 합니다.

데이터 행을 대상 테이블에 복사하는 동안 제약 조건 예외와 같은 예외가 throw되면 대리자를 errorHandler 호출합니다. FillErrorEventArgs 은 다음 값을 사용하여 대리자 errorHandler 에게 전달됩니다.

  • 속성은 Values 원본 데이터의 복사본으로 설정됩니다.

  • 속성은 DataTable 대상 DataTable로 설정됩니다.

  • 속성이 Errors catch된 예외로 설정됩니다.

Continue 대리자 호출이 반환된 후 속성이 읽혀집니다. 속성이 인 Continuetrue경우 원본 시퀀스는 계속해서 열거되고 데이터 테이블에 로드됩니다. 속성이 이 Continuefalse면 원래 예외가 메서드에서 CopyToDataTable throw됩니다.

자세한 내용은 쿼리에서 DataTable 만들기를 참조하세요.

적용 대상