Nyelv

DataTable.Rows Tulajdonság

Definíció

Lekéri a táblázathoz tartozó sorok gyűjteményét.

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

Tulajdonság értéke

Objektumokat DataRowCollection tartalmazó DataRow A.

Attribútumok

Példák

Az alábbiakban két példa látható a sorok visszaadására és beállítására. Az első példa a tulajdonságot Rows használja, és minden sorhoz kinyomtatja az egyes oszlopok értékét. A második példa az DataTable objektum metódusával NewRow hoz létre egy új DataRow objektumot a séma alapján DataTable. A sorértékek beállítása után a rendszer hozzáadja a sort a DataRowCollectionAdd metódushoz.

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

Megjegyzések

Új DataRowobjektum létrehozásához a NewRow metódus használatával kell visszaadnia egy új objektumot. Az ilyen objektumok automatikusan konfigurálva lesznek az objektumgyűjteményhez DataTable definiált DataColumn sémának megfelelően. Miután létrehozott egy új sort, és beállította a sor egyes oszlopainak értékeit, adja hozzá a sort a DataRowCollectionAdd metódushoz.

A gyűjtemény minden DataRow egyes tagja egy adatsort jelöl a táblában. A sor egyik oszlopának értékének módosításához meg kell hívnia a metódust AcceptChanges .

A következőre érvényes:

Lásd még