Export (0) Print
Expand All

DataRowCollection.Add Method (Object[])

Creates a row using specified values and adds it to the DataRowCollection.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

public DataRow Add (
	params Object[] values
)
public DataRow Add (
	Object[] values
)
public function Add (
	... values : Object[]
) : DataRow

Parameters

values

The array of values that are used to create the new row.

Return Value

A new DataRow.

Exception typeCondition

ArgumentException

The array is larger than the number of columns in the table.

InvalidCastException

A value does not match its respective column type.

ConstraintException

Adding the row invalidates a constraint.

NoNullAllowedException

Trying to put a null in a column where AllowDBNull is false.

If a DataColumn object has its AutoIncrement set to True, System.Object.Empty should be passed to get the default value for that column.

Exceptions can also occur if you generate an exception during either a ColumnChanging or RowChanging event. If an exception occurs, the row is not added to the table.

The following example uses the Add method to create and add a new DataRow object to a DataRowCollection.

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);


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft