DataTable.Rows Propriedade

Definição

Obtém a coleção de linhas que pertencem a essa tabela.

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 da propriedade

DataRowCollection

DataRowCollection que contém objetos de DataRow .

Atributos

Exemplos

O exemplo a seguir mostra dois exemplos de retorno e configuração de linhas. O primeiro exemplo usa a Rows propriedade e imprime o valor de cada coluna para cada linha. O segundo exemplo usa o DataTable método do NewRow objeto para criar um novo DataRow objeto com o esquema do DataTable. Depois de definir os valores de linha, a linha é adicionada ao DataRowCollection 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

Comentários

Para criar um novo DataRow, você deve usar o NewRow método para retornar um novo objeto. Esse objeto é configurado automaticamente de acordo com o esquema definido por DataTable meio de sua coleção de DataColumn objetos. Depois de criar uma nova linha e definir os valores de cada coluna na linha, adicione a linha ao DataRowCollection método usando Add .

Cada DataRow um na coleção representa uma linha de dados na tabela. Para confirmar uma alteração no valor de uma coluna na linha, você deve invocar o AcceptChanges método.

Aplica-se a

Confira também