DataTable.Rows Propriété

Définition

Obtient la collection des lignes qui appartiennent à cette table.

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

Valeur de propriété

Collection DataRowCollection qui contient des objets DataRow.

Attributs

Exemples

Voici deux exemples de retour et de définition de lignes. Le premier exemple utilise la Rows propriété et imprime la valeur de chaque colonne pour chaque ligne. Le deuxième exemple utilise la méthode de NewRow l’objet DataTable pour créer un objet DataRow avec le schéma de .DataTable Après avoir défini les valeurs de ligne, la ligne est ajoutée au via la DataRowCollectionAdd méthode .

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

Remarques

Pour créer un DataRow, vous devez utiliser la NewRow méthode pour retourner un nouvel objet. Un tel objet est automatiquement configuré en fonction du schéma défini pour via DataTable sa collection d’objets DataColumn . Après avoir créé une ligne et défini les valeurs pour chaque colonne de la ligne, ajoutez la ligne au à l’aide de DataRowCollection la Add méthode .

Chacun DataRow de la collection représente une ligne de données dans la table. Pour valider une modification de la valeur d’une colonne dans la ligne, vous devez appeler la AcceptChanges méthode .

S’applique à

Voir aussi