DataTable.Rows 속성

정의

이 테이블에 속한 행의 컬렉션을 가져옵니다.

public:
 property System::Data::DataRowCollection ^ Rows { System::Data::DataRowCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Data.DataRowCollection Rows { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataTableRowsDescr")]
public System.Data.DataRowCollection Rows { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Rows : System.Data.DataRowCollection
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataTableRowsDescr")>]
member this.Rows : System.Data.DataRowCollection
Public ReadOnly Property Rows As DataRowCollection

속성 값

DataRowCollection 개체를 포함하는 DataRow

특성

예제

다음은 행을 반환하고 설정하는 두 가지 예제를 보여 줍니다. 첫 번째 예제에서는 속성을 사용 하 고 Rows 모든 행에 대 한 각 열의 값을 인쇄 합니다. 두 번째 예제에서는 개체의 NewRow 메서드를 사용하여 DataTable 의 스키마를 사용하여 새 DataRow 개체를 만듭니다DataTable. 행 값을 설정하면 메서드를 통해 Add 행이 에 DataRowCollection 추가됩니다.

private void PrintRows(DataSet dataSet)
{
    // For each table in the DataSet, print the values of each row.
    foreach(DataTable thisTable in dataSet.Tables)
    {
        // For each row, print the values of each column.
        foreach(DataRow row in thisTable.Rows)
        {
            foreach(DataColumn column in thisTable.Columns)
            {
                Console.WriteLine(row[column]);
            }
        }
    }
}

private void AddARow(DataSet dataSet)
{
    DataTable table;
    table = dataSet.Tables["Suppliers"];
    // Use the NewRow method to create a DataRow with
    // the table's schema.
    DataRow newRow = table.NewRow();

    // Set values in the columns:
    newRow["CompanyID"] = "NewCompanyID";
    newRow["CompanyName"] = "NewCompanyName";

    // Add the row to the rows collection.
    table.Rows.Add(newRow);
}
Private Sub PrintRows(dataSet As DataSet)
     ' For each table in the DataSet, print the values of each row.
     Dim thisTable As DataTable
     For Each thisTable In  dataSet.Tables
         ' For each row, print the values of each column.
         Dim row As DataRow
         For Each row In  thisTable.Rows
             Dim column As DataColumn
             For Each column In  thisTable.Columns
                 Console.WriteLine(row(column))
             Next column
         Next row
     Next thisTable
End Sub
    
    
Private Sub AddARow(dataSet As DataSet)
    Dim table As DataTable = dataSet.Tables("Suppliers")
    ' Use the NewRow method to create a DataRow 
    'with the table's schema.
    Dim newRow As DataRow = table.NewRow()

    ' Set values in the columns:
    newRow("CompanyID") = "NewCompanyID"
    newRow("CompanyName") = "NewCompanyName"

    ' Add the row to the rows collection.
    table.Rows.Add(newRow)
End Sub

설명

DataRow를 만들려면 메서드를 NewRow 사용하여 새 개체를 반환해야 합니다. 이러한 개체는 개체의 컬렉션을 DataColumn 통해 에 대해 정의된 스키마에 DataTable 따라 자동으로 구성됩니다. 새 행을 만들고 행의 각 열에 대한 값을 설정한 후 메서드를 사용하여 Add 행을 에 DataRowCollection 추가합니다.

컬렉션의 각 DataRow 는 테이블의 데이터 행을 나타냅니다. 행의 열 값에 대한 변경 내용을 커밋하려면 메서드를 AcceptChanges 호출해야 합니다.

적용 대상

추가 정보