DataTable.Rows Proprietà

Definizione

Ottiene l'insieme di righe che appartengono a questa tabella.

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

Valore della proprietà

DataRowCollection

Oggetto DataRowCollection contenente oggetti DataRow.

Attributi

Esempio

Di seguito sono illustrati due esempi di restituzione e impostazione di righe. Il primo esempio usa la Rows proprietà e stampa il valore di ogni colonna per ogni riga. Il secondo esempio usa il DataTable metodo dell'oggetto NewRow per creare un nuovo DataRow oggetto con lo schema di DataTable. Dopo aver impostato i valori di riga, la riga viene aggiunta al DataRowCollection metodo tramite il Add metodo .

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

Commenti

Per creare un nuovo DataRowoggetto , è necessario usare il NewRow metodo per restituire un nuovo oggetto. Tale oggetto viene configurato automaticamente in base allo schema definito per l'insieme DataTable di DataColumn oggetti. Dopo aver creato una nuova riga e impostato i valori per ogni colonna nella riga, aggiungere la riga al DataRowCollection metodo usando il Add metodo .

Ogni DataRow elemento della raccolta rappresenta una riga di dati nella tabella. Per eseguire il commit di una modifica al valore di una colonna nella riga, è necessario richiamare il AcceptChanges metodo.

Si applica a

Vedi anche