DataSet.Load 메서드

정의

제공된 DataSet를 사용해서 IDataReader을 데이터 소스의 값으로 채웁니다.

오버로드

Load(IDataReader, LoadOption, DataTable[])

DataSet 인스턴스의 배열을 사용해 스키마 및 네임스페이스 정보를 제공하여, 제공된 IDataReader를 사용하는 데이터 소스의 값으로 DataTable을 채웁니다.

Load(IDataReader, LoadOption, String[])

문자열의 배열을 사용해 DataSet 내의 테이블에 대한 이름을 제공하여, 제공된 DataSet를 사용하는 데이터 소스의 값으로 IDataReader를 채웁니다.

Load(IDataReader, LoadOption, FillErrorEventHandler, DataTable[])

DataSet 인스턴스의 배열을 사용해 스키마 및 네임스페이스 정보를 제공하여, 제공된 IDataReader를 사용하는 데이터 소스의 값으로 DataTable을 채웁니다.

설명

메서드는 Load instance 검색된 데이터로 단일 DataTableIDataReader 채우는 기술을 제공합니다. 이 메서드는 동일한 기능을 제공하지만 에서 여러 결과 집합을 내DataSetIDataReader 여러 테이블로 로드할 수 있습니다.

DataSet에 이미 행이 포함되어 있으면 데이터 소스에서 들어오는 데이터가 기존 행과 병합됩니다.

메서드는 Load 지정된 데이터 원본에서 데이터를 가져오고 현재 데이터 컨테이너(이 경우 DataSet)에 추가하는 것을 중심으로 하는 몇 가지 일반적인 시나리오에서 사용할 수 있습니다. 이러한 시나리오에서는 업데이트 및 병합 동작을 DataSet설명하는 에 대한 표준 사용을 설명합니다.

DataSet 단일 기본 데이터 원본과 동기화하거나 업데이트합니다. 변경 DataSet 내용을 추적하여 기본 데이터 원본과의 동기화를 허용합니다. 또한 는 DataSet 하나 이상의 보조 데이터 원본에서 증분 데이터를 허용할 수 있습니다. 는 DataSet 보조 데이터 원본과의 동기화를 허용하기 위해 변경 내용을 추적할 책임이 없습니다.

이러한 두 가상 데이터 원본을 고려할 때 사용자는 다음 동작 중 하나가 필요할 수 있습니다.

  • 기본 데이터 원본에서 초기화 DataSet 합니다. 이 시나리오에서 사용자는 기본 데이터 원본의 값으로 빈 DataSet 을 초기화하려고 합니다. 하나 이상의 DataTable 콘텐츠가 수정됩니다. 나중에 사용자는 변경 내용을 기본 데이터 원본으로 다시 전파하려고 합니다.

  • 기본 데이터 원본에서 변경 내용을 보존하고 다시 동기화합니다. 이 시나리오에서 사용자는 이전 시나리오에서 채워진 를 가져와 DataSet 기본 데이터 원본과 증분 동기화를 수행하여 에서 DataSet수정한 내용을 유지하려고 합니다.

  • 보조 데이터 원본의 증분 데이터 피드입니다. 이 시나리오에서 사용자는 하나 이상의 보조 데이터 원본에서 변경 내용을 병합하고 해당 변경 내용을 기본 데이터 원본으로 다시 전파하려고 합니다.

메서드는 Load 이러한 모든 시나리오를 가능하게 합니다. 이 메서드를 사용하면 이미 에 있는 행이 로드되는 행과 결합되는 방식을 나타내는 로드 옵션 매개 변수를 DataTable 지정할 수 있습니다. 다음 표에서는 열거형에서 제공하는 세 가지 로드 옵션에 대해 LoadOption 설명합니다. 각 경우에 설명은 들어오는 데이터에 있는 행의 기본 키가 기존 행의 기본 키와 일치하는 경우의 동작을 나타냅니다.

로드 옵션 설명
PreserveChanges(기본값) 들어오는 행의 값을 사용하여 원래 버전의 행을 업데이트.
OverwriteChanges 현재 및 원래 버전의 행을 들어오는 행의 값으로 업데이트.
Upsert 현재 버전의 행을 들어오는 행의 값으로 업데이트.

일반적으로 PreserveChanges 및 옵션은 사용자가 및 OverwriteChanges 해당 변경 내용을 기본 데이터 원본과 동기화 DataSet 해야 하는 시나리오를 위한 것입니다. 옵션은 Upsert 하나 이상의 보조 데이터 원본에서 변경 내용을 쉽게 집계할 수 있도록 합니다.

Load(IDataReader, LoadOption, DataTable[])

Source:
DataSet.cs
Source:
DataSet.cs
Source:
DataSet.cs

DataSet 인스턴스의 배열을 사용해 스키마 및 네임스페이스 정보를 제공하여, 제공된 IDataReader를 사용하는 데이터 소스의 값으로 DataTable을 채웁니다.

public:
 void Load(System::Data::IDataReader ^ reader, System::Data::LoadOption loadOption, ... cli::array <System::Data::DataTable ^> ^ tables);
public void Load (System.Data.IDataReader reader, System.Data.LoadOption loadOption, params System.Data.DataTable[] tables);
member this.Load : System.Data.IDataReader * System.Data.LoadOption * System.Data.DataTable[] -> unit
Public Sub Load (reader As IDataReader, loadOption As LoadOption, ParamArray tables As DataTable())

매개 변수

reader
IDataReader

하나 이상의 결과 집합을 제공하는 IDataReader입니다.

loadOption
LoadOption

LoadOption 열거형의 값으로서, 이미 DataTableDataSet 인스턴스에 있는 행이 동일한 기본 키를 공유하는 들어오는 행과 결합되는 방식을 나타냅니다.

tables
DataTable[]

DataTable 메서드가 이름 및 네임스페이스 정보를 검색하는 Load(IDataReader, LoadOption, DataTable[]) 인스턴스의 배열입니다. 이러한 테이블은 각각 이 DataTableCollection에 포함된 DataSet의 멤버여야 합니다.

예제

다음 예제에서는 새 DataSet를 만들고 두 개의 DataTable 인스턴스를 에 DataSet추가한 다음 메서드를 사용하여 Load 를 채우고 DataSet 두 개의 결과 집합이 포함된 에서 DataTableReader 데이터를 검색합니다. 마지막으로 이 예제에서는 콘솔 창에 테이블의 내용을 표시합니다.

static void Main()
{
    DataSet dataSet = new DataSet();

    DataTable customerTable = new DataTable();
    DataTable productTable = new DataTable();

    // This information is cosmetic, only.
    customerTable.TableName = "Customers";
    productTable.TableName = "Products";

    // Add the tables to the DataSet:
    dataSet.Tables.Add(customerTable);
    dataSet.Tables.Add(productTable);

    // Load the data into the existing DataSet.
    DataTableReader reader = GetReader();
    dataSet.Load(reader, LoadOption.OverwriteChanges,
        customerTable, productTable);

    // Print out the contents of each table:
    foreach (DataTable table in dataSet.Tables)
    {
        PrintColumns(table);
    }

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetCustomers()
{
    // Create sample Customers table.
    DataTable table = new DataTable();
    table.TableName = "Customers";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Mary" });
    table.Rows.Add(new object[] { 1, "Andy" });
    table.Rows.Add(new object[] { 2, "Peter" });
    table.AcceptChanges();
    return table;
}

private static DataTable GetProducts()
{
    // Create sample Products table.
    DataTable table = new DataTable();
    table.TableName = "Products";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID",
        typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Wireless Network Card" });
    table.Rows.Add(new object[] { 1, "Hard Drive" });
    table.Rows.Add(new object[] { 2, "Monitor" });
    table.Rows.Add(new object[] { 3, "CPU" });
    table.AcceptChanges();
    return table;
}

private static void PrintColumns(DataTable table)
{
    Console.WriteLine();
    Console.WriteLine(table.TableName);
    Console.WriteLine("=========================");
    // Loop through all the rows in the table:
    foreach (DataRow row in table.Rows)
    {
        for (int i = 0; i < table.Columns.Count; i++)
        {
            Console.Write(row[i] + " ");
        }
        Console.WriteLine();
    }
}

private static DataTableReader GetReader()
{
    // Return a DataTableReader containing multiple
    // result sets, just for the sake of this demo.
    DataSet dataSet = new DataSet();
    dataSet.Tables.Add(GetCustomers());
    dataSet.Tables.Add(GetProducts());
    return dataSet.CreateDataReader();
}
Sub Main()
    Dim dataSet As New DataSet

    Dim customerTable As New DataTable
    Dim productTable As New DataTable

    ' This information is cosmetic, only.
    customerTable.TableName = "Customers"
    productTable.TableName = "Products"

    ' Add the tables to the DataSet:
    dataSet.Tables.Add(customerTable)
    dataSet.Tables.Add(productTable)

    ' Load the data into the existing DataSet. 
    Dim reader As DataTableReader = GetReader()
    dataSet.Load(reader, LoadOption.OverwriteChanges, _
        customerTable, productTable)

    ' Print out the contents of each table:
    For Each table As DataTable In dataSet.Tables
        PrintColumns(table)
    Next

    Console.WriteLine("Press any key to continue.")
    Console.ReadKey()
End Sub

Private Function GetCustomers() As DataTable
    ' Create sample Customers table.
    Dim table As New DataTable
    table.TableName = "Customers"

    ' Create two columns, ID and Name.
    Dim idColumn As DataColumn = table.Columns.Add("ID", _
        GetType(Integer))
    table.Columns.Add("Name", GetType(String))

    ' Set the ID column as the primary key column.
    table.PrimaryKey = New DataColumn() {idColumn}

    table.Rows.Add(New Object() {0, "Mary"})
    table.Rows.Add(New Object() {1, "Andy"})
    table.Rows.Add(New Object() {2, "Peter"})
    table.AcceptChanges()
    Return table
End Function

Private Function GetProducts() As DataTable
    ' Create sample Products table, in order
    ' to demonstrate the behavior of the DataTableReader.
    Dim table As New DataTable
    table.TableName = "Products"

    ' Create two columns, ID and Name.
    Dim idColumn As DataColumn = table.Columns.Add("ID", _
        GetType(Integer))
    table.Columns.Add("Name", GetType(String))

    ' Set the ID column as the primary key column.
    table.PrimaryKey = New DataColumn() {idColumn}

    table.Rows.Add(New Object() {0, "Wireless Network Card"})
    table.Rows.Add(New Object() {1, "Hard Drive"})
    table.Rows.Add(New Object() {2, "Monitor"})
    table.Rows.Add(New Object() {3, "CPU"})
    Return table
End Function

Private Function GetReader() As DataTableReader
    ' Return a DataTableReader containing multiple
    ' result sets, just for the sake of this demo.
    Dim dataSet As New DataSet
    dataSet.Tables.Add(GetCustomers())
    dataSet.Tables.Add(GetProducts())
    Return dataSet.CreateDataReader()
End Function

Private Sub PrintColumns( _
   ByVal table As DataTable)

    Console.WriteLine()
    Console.WriteLine(table.TableName)
    Console.WriteLine("=========================")
    ' Loop through all the rows in the table.
    For Each row As DataRow In table.Rows
        For Each col As DataColumn In table.Columns
            Console.Write(row(col).ToString() & " ")
        Next
        Console.WriteLine()
    Next
End Sub

설명

메서드는 Load instance 검색된 데이터로 단일 DataTableIDataReader 채우는 기술을 제공합니다. 이 메서드는 동일한 기능을 제공하지만 에서 여러 결과 집합을 내DataSetIDataReader 여러 테이블로 로드할 수 있습니다.

참고

들어오는 reader 원본 데이터 열이 계산 열인 경우 로드 작업이 실패 InvalidOperationException 합니다.

loadOption 매개 변수를 사용하면 가져온 데이터가 기존 데이터와 상호 작용하는 방법을 지정할 수 있으며 열거형의 값 LoadOption 중 하나를 사용할 수 있습니다. 이 매개 변수 사용에 대한 DataTableLoad 자세한 내용은 메서드에 대한 설명서를 참조하세요.

tables 매개 변수를 사용하면 판독기에서 로드된 각 결과 집합에 해당하는 테이블의 순서를 나타내는 인스턴스 배열 DataTable 을 지정할 수 있습니다. 메서드는 Load 제공된 DataTable 각 instance 원본 데이터 판독기에서 단일 결과 집합의 데이터로 채웁니다. 각 결과 집합 후에 메서드는 Load 더 이상 결과 집합이 없을 때까지 판독기 내의 다음 결과 집합으로 이동합니다.

이 메서드의 이름 확인 체계는 클래스의 DbDataAdapter 메서드 뒤에 오는 Fill 것과 동일합니다.

추가 정보

적용 대상

Load(IDataReader, LoadOption, String[])

Source:
DataSet.cs
Source:
DataSet.cs
Source:
DataSet.cs

문자열의 배열을 사용해 DataSet 내의 테이블에 대한 이름을 제공하여, 제공된 DataSet를 사용하는 데이터 소스의 값으로 IDataReader를 채웁니다.

public:
 void Load(System::Data::IDataReader ^ reader, System::Data::LoadOption loadOption, ... cli::array <System::String ^> ^ tables);
public void Load (System.Data.IDataReader reader, System.Data.LoadOption loadOption, params string[] tables);
member this.Load : System.Data.IDataReader * System.Data.LoadOption * string[] -> unit
Public Sub Load (reader As IDataReader, loadOption As LoadOption, ParamArray tables As String())

매개 변수

reader
IDataReader

하나 이상의 결과 집합을 제공하는 IDataReader입니다.

loadOption
LoadOption

LoadOption 열거형의 값으로서, 이미 DataTableDataSet 인스턴스에 있는 행이 동일한 기본 키를 공유하는 들어오는 행과 결합되는 방식을 나타냅니다.

tables
String[]

Load 메서드가 테이블 이름 정보를 검색하는 문자열의 배열입니다.

예제

다음 콘솔 애플리케이션 예제는 먼저 테이블을 만듭니다 및에 판독기에서 데이터를 로드 한 DataSet를 사용 하 여는 Load 메서드. 그런 다음, 에 테이블을 DataSet 추가하고 의 데이터 DataTableReader로 테이블을 채우려고 시도합니다. 이 예제에서는 메서드에 Load 전달된 매개 변수가 존재하지 않는 테이블 이름을 나타내기 때문에 메서드는 Load 매개 변수로 전달된 이름과 일치하도록 새 테이블을 만듭니다. 데이터가 로드되면 이 예제에서는 콘솔 창에 모든 테이블의 내용을 표시합니다.

static void Main()
{
    DataSet dataSet = new DataSet();

    DataTableReader reader = GetReader();

    // The tables listed as parameters for the Load method
    // should be in the same order as the tables within the IDataReader.
    dataSet.Load(reader, LoadOption.Upsert, "Customers", "Products");
    foreach (DataTable table in dataSet.Tables)
    {
        PrintColumns(table);
    }

    // Now try the example with the DataSet
    // already filled with data:
    dataSet = new DataSet();
    dataSet.Tables.Add(GetCustomers());
    dataSet.Tables.Add(GetProducts());

    // Retrieve a data reader containing changed data:
    reader = GetReader();

    // Load the data into the existing DataSet. Retrieve the order of the
    // the data in the reader from the
    // list of table names in the parameters. If you specify
    // a new table name here, the Load method will create
    // a corresponding new table.
    dataSet.Load(reader, LoadOption.Upsert,
        "NewCustomers", "Products");
    foreach (DataTable table in dataSet.Tables)
    {
        PrintColumns(table);
    }

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetCustomers()
{
    // Create sample Customers table.
    DataTable table = new DataTable();
    table.TableName = "Customers";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Mary" });
    table.Rows.Add(new object[] { 1, "Andy" });
    table.Rows.Add(new object[] { 2, "Peter" });
    table.AcceptChanges();
    return table;
}

private static DataTable GetProducts()
{
    // Create sample Products table.
    DataTable table = new DataTable();
    table.TableName = "Products";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Wireless Network Card" });
    table.Rows.Add(new object[] { 1, "Hard Drive" });
    table.Rows.Add(new object[] { 2, "Monitor" });
    table.Rows.Add(new object[] { 3, "CPU" });
    table.AcceptChanges();
    return table;
}

private static void PrintColumns(DataTable table)
{
    Console.WriteLine();
    Console.WriteLine(table.TableName);
    Console.WriteLine("=========================");
    // Loop through all the rows in the table:
    foreach (DataRow row in table.Rows)
    {
        for (int i = 0; i < table.Columns.Count; i++)
        {
            Console.Write(row[i] + " ");
        }
        Console.WriteLine();
    }
}

private static DataTableReader GetReader()
{
    // Return a DataTableReader containing multiple
    // result sets, just for the sake of this demo.
    DataSet dataSet = new DataSet();
    dataSet.Tables.Add(GetCustomers());
    dataSet.Tables.Add(GetProducts());
    return dataSet.CreateDataReader();
}
Sub Main()
  Dim dataSet As New DataSet
  Dim table As DataTable

  Dim reader As DataTableReader = GetReader()

  ' The tables listed as parameters for the Load method 
  ' should be in the same order as the tables within the IDataReader.
  dataSet.Load(reader, LoadOption.Upsert, "Customers", "Products")
  For Each table In dataSet.Tables
    PrintColumns(table)
  Next

  ' Now try the example with the DataSet
  ' already filled with data:
  dataSet = New DataSet
  dataSet.Tables.Add(GetCustomers())
  dataSet.Tables.Add(GetProducts())

  ' Retrieve a data reader containing changed data:
  reader = GetReader()

  ' Load the data into the existing DataSet. Retrieve the order of the
  ' the data in the reader from the
  ' list of table names in the parameters. If you specify
  ' a new table name here, the Load method will create
  ' a corresponding new table.
  dataSet.Load(reader, LoadOption.Upsert, "NewCustomers", "Products")
  For Each table In dataSet.Tables
    PrintColumns(table)
  Next

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Function GetCustomers() As DataTable
  ' Create sample Customers table.
  Dim table As New DataTable
  table.TableName = "Customers"

  ' Create two columns, ID and Name.
  Dim idColumn As DataColumn = table.Columns.Add("ID", GetType(Integer))
  table.Columns.Add("Name", GetType(String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {0, "Mary"})
  table.Rows.Add(New Object() {1, "Andy"})
  table.Rows.Add(New Object() {2, "Peter"})
  table.AcceptChanges()
  Return table
End Function

Private Function GetProducts() As DataTable
  ' Create sample Products table, in order
  ' to demonstrate the behavior of the DataTableReader.
  Dim table As New DataTable
  table.TableName = "Products"

  ' Create two columns, ID and Name.
  Dim idColumn As DataColumn = table.Columns.Add("ID", GetType(Integer))
  table.Columns.Add("Name", GetType(String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {0, "Wireless Network Card"})
  table.Rows.Add(New Object() {1, "Hard Drive"})
  table.Rows.Add(New Object() {2, "Monitor"})
  table.Rows.Add(New Object() {3, "CPU"})
  Return table
End Function

Private Function GetReader() As DataTableReader
  ' Return a DataTableReader containing multiple
  ' result sets, just for the sake of this demo.
  Dim dataSet As New DataSet
  dataSet.Tables.Add(GetCustomers())
  dataSet.Tables.Add(GetProducts())
  Return dataSet.CreateDataReader()
End Function

Private Sub PrintColumns( _
   ByVal table As DataTable)

  Console.WriteLine()
  Console.WriteLine(table.TableName)
  Console.WriteLine("=========================")
  ' Loop through all the rows in the table.
  For Each row As DataRow In table.Rows
    For Each col As DataColumn In table.Columns
      Console.Write(row(col).ToString() & " ")
    Next
    Console.WriteLine()
  Next
End Sub

설명

메서드는 Load instance 검색된 데이터로 단일 DataTableIDataReader 채우는 기술을 제공합니다. 이 메서드는 동일한 기능을 제공하지만 에서 여러 결과 집합을 내DataSetIDataReader 여러 테이블로 로드할 수 있습니다.

참고

들어오는 reader 원본 데이터 열이 계산 열인 경우 로드 작업이 실패 InvalidOperationException 합니다.

loadOption 매개 변수를 사용하면 가져온 데이터가 기존 데이터와 상호 작용하는 방법을 지정할 수 있으며 열거형의 값 LoadOption 중 하나를 사용할 수 있습니다. 이 매개 변수 사용에 대한 Load 자세한 내용은 메서드에 대한 설명서를 참조하세요.

tables 매개 변수를 사용하면 판독기에서 로드된 각 결과 집합에 해당하는 테이블의 순서를 나타내는 테이블 이름 배열을 지정할 수 있습니다. 메서드는 Load 테이블 DataSet 이름 배열에 있는 이름과 일치하는 내의 테이블을 순서대로 찾으려고 시도합니다. 일치하는 테이블이 있으면 해당 테이블이 현재 결과 집합의 내용과 함께 로드됩니다. 일치하는 테이블을 찾을 수 없는 경우 테이블 이름 배열에 제공된 이름을 사용하여 테이블이 만들어지고 새 테이블의 스키마가 결과 집합에서 유추됩니다. 각 결과 집합 후에 메서드는 Load 더 이상 결과 집합이 없을 때까지 판독기 내의 다음 결과 집합으로 이동합니다.

에 연결된 DataSet기본 네임스페이스(있는 경우)는 새로 만든 DataTable각 와 연결됩니다. 이 메서드의 이름 확인 체계는 클래스의 DbDataAdapter 메서드 뒤에 오는 Fill 것과 동일합니다.

추가 정보

적용 대상

Load(IDataReader, LoadOption, FillErrorEventHandler, DataTable[])

Source:
DataSet.cs
Source:
DataSet.cs
Source:
DataSet.cs

DataSet 인스턴스의 배열을 사용해 스키마 및 네임스페이스 정보를 제공하여, 제공된 IDataReader를 사용하는 데이터 소스의 값으로 DataTable을 채웁니다.

public:
 virtual void Load(System::Data::IDataReader ^ reader, System::Data::LoadOption loadOption, System::Data::FillErrorEventHandler ^ errorHandler, ... cli::array <System::Data::DataTable ^> ^ tables);
public virtual void Load (System.Data.IDataReader reader, System.Data.LoadOption loadOption, System.Data.FillErrorEventHandler? errorHandler, params System.Data.DataTable[] tables);
public virtual void Load (System.Data.IDataReader reader, System.Data.LoadOption loadOption, System.Data.FillErrorEventHandler errorHandler, params System.Data.DataTable[] tables);
abstract member Load : System.Data.IDataReader * System.Data.LoadOption * System.Data.FillErrorEventHandler * System.Data.DataTable[] -> unit
override this.Load : System.Data.IDataReader * System.Data.LoadOption * System.Data.FillErrorEventHandler * System.Data.DataTable[] -> unit
Public Overridable Sub Load (reader As IDataReader, loadOption As LoadOption, errorHandler As FillErrorEventHandler, ParamArray tables As DataTable())

매개 변수

reader
IDataReader

하나 이상의 결과 집합을 제공하는 IDataReader입니다.

loadOption
LoadOption

LoadOption 열거형의 값으로서, 이미 DataTableDataSet 인스턴스에 있는 행이 동일한 기본 키를 공유하는 들어오는 행과 결합되는 방식을 나타냅니다.

errorHandler
FillErrorEventHandler

데이터를 로드하는 동안 오류가 발생하면 호출할 FillErrorEventHandler 대리자입니다.

tables
DataTable[]

DataTable 메서드가 이름 및 네임스페이스 정보를 검색하는 Load(IDataReader, LoadOption, FillErrorEventHandler, DataTable[]) 인스턴스의 배열입니다.

예제

다음 예제에서는 에 테이블을 추가한 DataSet다음 메서드를 사용하여 Load 호환되지 않는 스키마가 포함된 에서 DataTableReader 데이터를 로드하려고 시도합니다. 이 예제에서는 오류를 트래핑하는 대신 대리자를 FillErrorEventHandler 사용하여 오류를 조사하고 처리합니다. 출력이 콘솔 창에 표시됩니다.

static void Main()
{
    // Attempt to load data from a data reader in which
    // the schema is incompatible with the current schema.
    // If you use exception handling, you won't get the chance
    // to examine each row, and each individual table,
    // as the Load method progresses.
    // By taking advantage of the FillErrorEventHandler delegate,
    // you can interact with the Load process as an error occurs,
    // attempting to fix the problem, or simply continuing or quitting
    // the Load process.:
    DataSet dataSet = new DataSet();
    DataTable table = GetIntegerTable();
    dataSet.Tables.Add(table);
    DataTableReader reader = new DataTableReader(GetStringTable());
    dataSet.Load(reader, LoadOption.OverwriteChanges,
        FillErrorHandler, table);

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetIntegerTable()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 4 });
    table.Rows.Add(new object[] { 5 });
    table.AcceptChanges();
    return table;
}

private static DataTable GetStringTable()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { "Mary" });
    table.Rows.Add(new object[] { "Andy" });
    table.Rows.Add(new object[] { "Peter" });
    table.AcceptChanges();
    return table;
}

static void FillErrorHandler(object sender, FillErrorEventArgs e)
{
    // You can use the e.Errors value to determine exactly what
    // went wrong.
    if (e.Errors.GetType() == typeof(System.FormatException))
    {
        Console.WriteLine("Error when attempting to update the value: {0}",
            e.Values[0]);
    }

    // Setting e.Continue to True tells the Load
    // method to continue trying. Setting it to False
    // indicates that an error has occurred, and the
    // Load method raises the exception that got
    // you here.
    e.Continue = true;
}
Sub Main()
  Dim dataSet As New DataSet
  Dim table As New DataTable()

  ' Attempt to load data from a data reader in which
  ' the schema is incompatible with the current schema.
  ' If you use exception handling, you won't get the chance
  ' to examine each row, and each individual table,
  ' as the Load method progresses.
  ' By taking advantage of the FillErrorEventHandler delegate,
  ' you can interact with the Load process as an error occurs,
  ' attempting to fix the problem, or simply continuing or quitting
  ' the Load process.:
  dataSet = New DataSet()
  table = GetIntegerTable()
  dataSet.Tables.Add(table)
  Dim reader As New DataTableReader(GetStringTable())
  dataSet.Load(reader, LoadOption.OverwriteChanges, _
      AddressOf FillErrorHandler, table)

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Sub FillErrorHandler(ByVal sender As Object, _
  ByVal e As FillErrorEventArgs)
  ' You can use the e.Errors value to determine exactly what
  ' went wrong.
  If e.Errors.GetType Is GetType(System.FormatException) Then
    Console.WriteLine("Error when attempting to update the value: {0}", _
      e.Values(0))
  End If

  ' Setting e.Continue to True tells the Load
  ' method to continue trying. Setting it to False
  ' indicates that an error has occurred, and the 
  ' Load method raises the exception that got 
  ' you here.
  e.Continue = True
End Sub

Private Function GetIntegerTable() As DataTable
  ' Create sample table with a single Int32 column.
  Dim table As New DataTable

  Dim idColumn As DataColumn = table.Columns.Add("ID", _
      GetType(Integer))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {4})
  table.Rows.Add(New Object() {5})
  table.TableName = "IntegerTable"
  table.AcceptChanges()
  Return table
End Function

Private Function GetStringTable() As DataTable
  ' Create sample table with a single String column.
  Dim table As New DataTable

  Dim idColumn As DataColumn = table.Columns.Add("ID", _
      GetType(String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {"Mary"})
  table.Rows.Add(New Object() {"Andy"})
  table.Rows.Add(New Object() {"Peter"})
  table.AcceptChanges()
  Return table
End Function

Private Sub PrintColumns( _
   ByVal table As DataTable)

  ' Loop through all the rows in the DataTableReader.
  For Each row As DataRow In table.Rows
    For Each col As DataColumn In table.Columns
      Console.Write(row(col).ToString() & " ")
    Next
    Console.WriteLine()
  Next
End Sub

설명

메서드는 Load instance 검색된 데이터로 단일 DataTableIDataReader 채우는 기술을 제공합니다. 이 메서드는 동일한 기능을 제공하지만 에서 여러 결과 집합을 내DataSetIDataReader 여러 테이블로 로드할 수 있습니다.

참고

들어오는 reader 원본 데이터 열이 계산 열인 경우 로드 작업이 실패 InvalidOperationException 합니다.

loadOption 매개 변수를 사용하면 가져온 데이터가 기존 데이터와 상호 작용하는 방법을 지정할 수 있으며 열거형의 값 LoadOption 중 하나를 사용할 수 있습니다. 이 매개 변수 사용에 대한 DataTableLoad 자세한 내용은 메서드에 대한 설명서를 참조하세요.

errorHandler 매개 변수는 FillErrorEventHandler 데이터를 로드하는 동안 오류가 발생할 때 호출되는 프로시저를 참조하는 대리자입니다. 프로시저에 전달된 매개 변수는 FillErrorEventArgs 발생한 오류, 현재 데이터 행 및 DataTable 채워지는 에 대한 정보를 검색할 수 있는 속성을 제공합니다. 더 간단한 try/catch 블록이 아닌 이 대리자 메커니즘을 사용하면 오류를 확인하고, 상황을 처리하고, 원하는 경우 처리를 계속할 수 있습니다. 매개 변수는 FillErrorEventArgs 속성을 제공합니다 Continue . 이 속성을 true 로 설정하여 오류를 처리하고 처리를 계속하려고 함을 나타내고, 처리를 중지할 것임을 나타내도록 속성을 false 로 설정합니다. 속성을 false 로 설정하면 문제를 트리거한 코드가 예외를 throw합니다.

tables 매개 변수를 사용하면 판독기에서 로드된 각 결과 집합에 해당하는 테이블의 순서를 나타내는 인스턴스 배열 DataTable 을 지정할 수 있습니다. 메서드는 Load 제공된 DataTable 각 instance 원본 데이터 판독기에서 단일 결과 집합의 데이터로 채웁니다. 각 결과 집합 후에 메서드는 Load 더 이상 결과 집합이 없을 때까지 판독기 내의 다음 결과 집합으로 이동합니다.

이 메서드의 이름 확인 체계는 클래스의 DbDataAdapter 메서드 뒤에 오는 Fill 것과 동일합니다.

추가 정보

적용 대상