DataTable.Rows Özellik
Tanım
Bu tabloya ait olan satırların koleksiyonunu alır.Gets the collection of rows that belong to this table.
public:
property System::Data::DataRowCollection ^ Rows { System::Data::DataRowCollection ^ get(); };
public System.Data.DataRowCollection Rows { 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; }
member this.Rows : System.Data.DataRowCollection
[<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
Özellik Değeri
DataRowCollectionNesneler içeren bir DataRow , aksi takdirde bir nesne yoksa null değer DataRow .A DataRowCollection that contains DataRow objects; otherwise a null value if no DataRow objects exist.
- Öznitelikler
Örnekler
Aşağıda, satırları döndürmeyle ve ayarlamaya yönelik iki örnek gösterilmektedir.The following shows two examples of returning and setting rows. İlk örnek, özelliğini kullanır Rows ve her satır için her bir sütunun değerini yazdırır.The first example uses the Rows property and prints the value of each column for every row. İkinci örnek DataTable NewRow , şemasına sahip yeni bir nesne oluşturmak için nesnesinin yöntemini kullanır DataRow DataTable .The second example uses the DataTable object's NewRow method to create a new DataRow object with the schema of the DataTable. Satır değerlerini ayarladıktan sonra, satır DataRowCollection yöntemine aracılığıyla öğesine eklenir Add
.After setting the row values, the row is added to the DataRowCollection through the Add
method.
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
Açıklamalar
Yeni bir nesnesi oluşturmak için DataRow , NewRow yöntemini kullanarak yeni bir nesne döndürün.To create a new DataRow, you must use the NewRow method to return a new object. Böyle bir nesne, nesne koleksiyonu aracılığıyla için tanımlanan şemaya göre otomatik olarak yapılandırılır DataTable DataColumn .Such an object is automatically configured according to the schema defined for the DataTable through its collection of DataColumn objects. Yeni bir satır oluşturup satırdaki her sütun için değerleri ayarladıktan sonra, yöntemini kullanarak satırı öğesine ekleyin DataRowCollection Add
.After creating a new row and setting the values for each column in the row, add the row to the DataRowCollection using the Add
method.
DataRowKoleksiyondaki her bir tablo, tablodaki bir veri satırını temsil eder.Each DataRow in the collection represents a row of data in the table. Satırdaki bir sütunun değerinde bir değişikliği yürütmek için yöntemini çağırmanız gerekir AcceptChanges .To commit a change to the value of a column in the row, you must invoke the AcceptChanges method.