DataTable.Rows Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém a coleção de linhas que pertencem a esta tabela.
public:
property System::Data::DataRowCollection ^ Rows { System::Data::DataRowCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataTableRowsDescr")]
public System.Data.DataRowCollection Rows { get; }
[System.ComponentModel.Browsable(false)]
public System.Data.DataRowCollection Rows { get; }
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataTableRowsDescr")>]
member this.Rows : System.Data.DataRowCollection
[<System.ComponentModel.Browsable(false)>]
member this.Rows : System.Data.DataRowCollection
Public ReadOnly Property Rows As DataRowCollection
Valor de Propriedade
A DataRowCollection que contém DataRow objetos.
- Atributos
Exemplos
O que se segue mostra dois exemplos de linhas de retorno e de colocação. 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 das linhas, a linha é adicionada ao DataRowCollection através do 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
Observações
Para criar um novo DataRow, deve usar o NewRow método para devolver um novo objeto. Tal objeto é automaticamente configurado de acordo com o esquema definido para o DataTable através da sua coleção de DataColumn objetos. Depois de criar uma nova linha e definir os valores para cada coluna da linha, adicione a linha ao DataRowCollection usando o Add método.
Cada DataRow uma na coleção representa uma linha de dados na tabela. Para comprometer uma alteração do valor de uma coluna na linha, deve invocar o AcceptChanges método.