DataRowCollection.Add Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
DataRow'e DataRowCollection ekler.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| Add(DataRow) |
Belirtilen DataRow öğesini nesnesine DataRowCollection ekler. |
| Add(Object[]) |
Belirtilen değerleri kullanarak bir satır oluşturur ve bunu öğesine DataRowCollectionekler. |
Add(DataRow)
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
Belirtilen DataRow öğesini nesnesine DataRowCollection ekler.
public:
void Add(System::Data::DataRow ^ row);
public void Add(System.Data.DataRow row);
member this.Add : System.Data.DataRow -> unit
Public Sub Add (row As DataRow)
Parametreler
Özel durumlar
Satır null.
Satır başka bir tabloya ait veya zaten bu tabloya ait.
Ekleme bir kısıtlamayı geçersiz kıyor.
Ekleme, false olan bir DataColumn konuma AllowDBNull null koymaya çalışır.
Örnekler
Aşağıdaki örnek, bir nesneye yeni Add eklemek için DataRow yöntemini kullanırDataRowCollection.
private void ShowRows(DataTable table)
{
// Print the number of rows in the collection.
Console.WriteLine(table.Rows.Count);
// Print the value of columns 1 in each row
foreach(DataRow row in table.Rows)
{
Console.WriteLine(row[1]);
}
}
private void AddRow(DataTable table)
{
DataRowCollection rowCollection = table.Rows;
// Instantiate a new row using the NewRow method.
DataRow newRow = table.NewRow();
// Insert code to fill the row with values.
// Add the row to the DataRowCollection.
table.Rows.Add(newRow);
}
Private Sub ShowRows(Byval table As DataTable)
' Print the number of rows in the collection.
Console.WriteLine(table.Rows.Count)
Dim row As DataRow
' Print the value of columns 1 in each row
For Each row In table.Rows
Console.WriteLine(row(1))
Next
End Sub
Private Sub AddRow(ByVal table As DataTable)
' Instantiate a new row using the NewRow method.
Dim newRow As DataRow = table.NewRow()
' Insert code to fill the row with values.
' Add the row to the DataRowCollection.
table.Rows.Add(newRow)
End Sub
Açıklamalar
Yeni DataRowbir oluşturmak için sınıfının yöntemini NewRow kullanmanız DataTable gerekir. yöntemini kullandığınızda, üst NewRowöğesinin DataRow şeması kullanılarak yeni DataTable bir nesne döndürülür. Nesnesini oluşturduktan DataRow ve sütunlarının her biri için değerleri ayarladıktan sonra yöntemini kullanarak Add nesneyi koleksiyona ekleyin.
Kullanıcı olayda RowChanging bir özel durum oluşturursa bir özel durum oluşturur. Özel durum oluşursa, satır tabloya eklenmez.
Ayrıca bkz.
Şunlara uygulanır
Add(Object[])
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
- Kaynak:
- DataRowCollection.cs
Belirtilen değerleri kullanarak bir satır oluşturur ve bunu öğesine DataRowCollectionekler.
public:
System::Data::DataRow ^ Add(... cli::array <System::Object ^> ^ values);
public:
virtual System::Data::DataRow ^ Add(cli::array <System::Object ^> ^ values);
public System.Data.DataRow Add(params object?[] values);
public System.Data.DataRow Add(params object[] values);
public virtual System.Data.DataRow Add(object[] values);
member this.Add : obj[] -> System.Data.DataRow
abstract member Add : obj[] -> System.Data.DataRow
override this.Add : obj[] -> System.Data.DataRow
Public Function Add (ParamArray values As Object()) As DataRow
Public Overridable Function Add (values As Object()) As DataRow
Parametreler
- values
- Object[]
Yeni satırı oluşturmak için kullanılan değer dizisi.
Döndürülenler
Yeni satır.
Özel durumlar
Dizi, tablodaki sütun sayısından daha büyük.
Değer ilgili sütun türüyle eşleşmiyor.
Satırın eklenmesi bir kısıtlamayı geçersiz kıyor.
False olan AllowDBNull bir sütuna null koymaya çalışılıyor.
Örnekler
Aşağıdaki örnek, oluşturmak ve öğesine yeni Add bir nesne eklemek için DataRowyöntemini kullanırDataRowCollection.
private void AddRow(DataTable table)
{
// Create an array with three elements.
object[] rowVals = new object[3];
DataRowCollection rowCollection = table.Rows;
rowVals[0] = "hello";
rowVals[1] = "world";
rowVals[2] = "two";
// Add and return the new row.
DataRow row = rowCollection.Add(rowVals);
}
Private Sub AddRow(ByVal table As DataTable)
' Create an array with three elements.
Dim rowVals(2) As Object
Dim rowCollection As DataRowCollection = table.Rows
rowVals(0) = "hello"
rowVals(1) = "world"
rowVals(2) = "two"
' Add and return the new row.
Dim row As DataRow = rowCollection.Add(rowVals)
End Sub
Açıklamalar
Nesnenin DataColumnAutoIncrement değeri True olarak ayarlanmışsa, bu sütun için varsayılan değeri almak için null değeri geçirilmelidir.
Bir veya ColumnChanging olayı sırasında bir özel durum oluşturursanız da RowChanging özel durumlar oluşabilir. Özel durum oluşursa, satır tabloya eklenmez.