DataTable.Rows Propiedad

Definición

Obtiene la colección de filas que pertenecen a esta tabla.

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

Valor de propiedad

DataRowCollection que contiene objetos DataRow.

Atributos

Ejemplos

A continuación se muestran dos ejemplos de devolución y configuración de filas. En el primer ejemplo se usa la Rows propiedad y se imprime el valor de cada columna para cada fila. En el segundo ejemplo se usa el método del NewRow objeto para crear un nuevo DataRow objeto con el esquema de DataTable.DataTable Después de establecer los valores de fila, la fila se agrega al DataRowCollection a través del Add método .

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

Comentarios

Para crear un objeto , DataRowdebe usar el NewRow método para devolver un nuevo objeto . Este objeto se configura automáticamente según el esquema definido para a DataTable través de su colección de DataColumn objetos . Después de crear una nueva fila y establecer los valores de cada columna de la fila, agregue la fila al DataRowCollection mediante el Add método .

Cada DataRow una de las colecciones representa una fila de datos de la tabla. Para confirmar un cambio en el valor de una columna de la fila, debe invocar el AcceptChanges método .

Se aplica a

Consulte también