DataTableReader 생성자

정의

DataTableReader 클래스의 새 인스턴스를 초기화합니다.

오버로드

DataTableReader(DataTable)

제공된 DataTableReader의 데이터를 사용하여 DataTable 클래스의 새 인스턴스를 초기화합니다.

DataTableReader(DataTable[])

DataTableReader 개체의 제공된 배열을 사용하여 DataTable 클래스의 새 인스턴스를 초기화합니다.

DataTableReader(DataTable)

Source:
DataTableReader.cs
Source:
DataTableReader.cs
Source:
DataTableReader.cs

제공된 DataTableReader의 데이터를 사용하여 DataTable 클래스의 새 인스턴스를 초기화합니다.

public:
 DataTableReader(System::Data::DataTable ^ dataTable);
public DataTableReader (System.Data.DataTable dataTable);
new System.Data.DataTableReader : System.Data.DataTable -> System.Data.DataTableReader
Public Sub New (dataTable As DataTable)

매개 변수

dataTable
DataTable

DataTable가 결과 집합을 가져오는 DataTableReader입니다.

적용 대상

DataTableReader(DataTable[])

Source:
DataTableReader.cs
Source:
DataTableReader.cs
Source:
DataTableReader.cs

DataTableReader 개체의 제공된 배열을 사용하여 DataTable 클래스의 새 인스턴스를 초기화합니다.

public:
 DataTableReader(cli::array <System::Data::DataTable ^> ^ dataTables);
public DataTableReader (System.Data.DataTable[] dataTables);
new System.Data.DataTableReader : System.Data.DataTable[] -> System.Data.DataTableReader
Public Sub New (dataTables As DataTable())

매개 변수

dataTables
DataTable[]

DataTable 개체의 결과를 제공하는 DataTableReader 개체의 배열입니다.

예제

다음 예에서 TestConstructor 메서드 두 개 만듭니다 DataTable 인스턴스. 이 생성자를 보여 주기 위해 합니다 DataTableReader 클래스, 예제에서는 새 DataTableReader 두 가지를 포함 하는 배열을 기반으로 DataTables, 콘솔에 처음 몇 개의 열에서 콘텐츠를 인쇄 하는 간단한 작업을 수행 하 고 창입니다. 이 애플리케이션을 테스트 하려면 새 콘솔 애플리케이션을 만들고 새로 만든된 파일에 샘플 코드를 붙여넣습니다.

private static void TestConstructor()
{
    // Create two data adapters, one for each of the two
    // DataTables to be filled.
    DataTable customerDataTable = GetCustomers();
    DataTable productDataTable = GetProducts();

    // Create the new DataTableReader.
    using (DataTableReader reader = new DataTableReader(
               new DataTable[] { customerDataTable, productDataTable }))
    {
        // Print the contents of each of the result sets.
        do
        {
            PrintColumns(reader);
        } while (reader.NextResult());
    }

    Console.WriteLine("Press Enter to finish.");
    Console.ReadLine();
}

private static DataTable GetCustomers()
{
    // 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));
    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[] { 1, "Mary" });
    table.Rows.Add(new object[] { 2, "Andy" });
    table.Rows.Add(new object[] { 3, "Peter" });
    table.Rows.Add(new object[] { 4, "Russ" });
    return table;
}

private static DataTable GetProducts()
{
    // Create sample Products 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));
    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[] { 1, "Wireless Network Card" });
    table.Rows.Add(new object[] { 2, "Hard Drive" });
    table.Rows.Add(new object[] { 3, "Monitor" });
    table.Rows.Add(new object[] { 4, "CPU" });
    return table;
}

private static void PrintColumns(DataTableReader reader)
{
    // Loop through all the rows in the DataTableReader
    while (reader.Read())
    {
        for (int i = 0; i < reader.FieldCount; i++)
        {
            Console.Write(reader[i] + " ");
        }
        Console.WriteLine();
    }
}
Private Sub TestConstructor()
   ' Create two data adapters, one for each of the two
   ' DataTables to be filled.
   Dim customerDataTable As DataTable = GetCustomers()
   Dim productDataTable As DataTable = GetProducts()

   ' Create the new DataTableReader.
   Using reader As New DataTableReader( _
      New DataTable() {customerDataTable, productDataTable})

      ' Print the contents of each of the result sets.
      Do
         PrintColumns(reader)
      Loop While reader.NextResult()
   End Using

   Console.WriteLine("Press Enter to finish.")
   Console.ReadLine()

End Sub

Private Function GetCustomers() As DataTable
   ' Create sample Customers table, in order
   ' to demonstrate the behavior of the DataTableReader.
   Dim table As New DataTable

   ' 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() {1, "Mary"})
   table.Rows.Add(New Object() {2, "Andy"})
   table.Rows.Add(New Object() {3, "Peter"})
   table.Rows.Add(New Object() {4, "Russ"})
   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

   ' 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() {1, "Wireless Network Card"})
   table.Rows.Add(New Object() {2, "Hard Drive"})
   table.Rows.Add(New Object() {3, "Monitor"})
   table.Rows.Add(New Object() {4, "CPU"})
   Return table
End Function

Private Sub PrintColumns( _
   ByVal reader As DataTableReader)

   ' Loop through all the rows in the DataTableReader.
   Do While reader.Read()
      For i As Integer = 0 To reader.FieldCount - 1
         Console.Write(reader(i).ToString() & " ")
      Next
      Console.WriteLine()
   Loop
End Sub

콘솔 창에는 다음과 같은 결과가 표시 됩니다.

1 Mary  
2 Andy  
3 Peter  
4 Russ  
1 Wireless Network Card  
2 Hard Drive  
3 Monitor  
4 CPU  

설명

만들어야 하는 경우는 DataTableReader 모든 또는 특정에 있는 테이블의 하위 집합에 따라 DataSet, 호출을 DataSetCreateDataReader 메서드. 새 않으려면 DataTableReader 의 그룹을 기반으로 하는 인스턴스 DataTable 않는 인스턴스가 고 그렇지 관련이 생성자를 사용 합니다. 순서 다시 정렬 하려면이 생성자의 활용도 합니다 DataTables 내에서 DataTableReader이면 해당 원본 내에서 순서 DataSet 요구를 충족 하지 않습니다.

적용 대상