다음을 통해 공유


DataTable.Rows 속성

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

네임스페이스: System.Data
어셈블리: System.Data(system.data.dll)

구문

‘선언
Public ReadOnly Property Rows As DataRowCollection
‘사용 방법
Dim instance As DataTable
Dim value As DataRowCollection

value = instance.Rows
public DataRowCollection Rows { get; }
public:
property DataRowCollection^ Rows {
    DataRowCollection^ get ();
}
/** @property */
public DataRowCollection get_Rows ()
public function get Rows () : DataRowCollection

속성 값

DataRow 개체가 포함된 DataRowCollection이거나, DataRow 개체가 없으면 null 값입니다.

설명

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

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

예제

다음 두 예제에서는 행을 반환하고 설정하는 방법을 보여 줍니다. 첫 번째 예제에서는 Rows 속성을 사용하고 모든 행의 각 열 값을 출력합니다. 두 번째 예제에서는 DataTable 개체의 NewRow 메서드를 사용하여 DataTable의 스키마가 있는 새 DataRow 개체를 만듭니다. 행 값을 설정한 다음에는 Add 메서드를 사용하여 해당 행을 DataRowCollection에 추가합니다.

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
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);
}

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

DataTable 클래스
DataTable 멤버
System.Data 네임스페이스
AcceptChanges
DataRow 클래스
DataRowCollection 클래스
NewRow

기타 리소스

DataTable 작성 및 사용