DataTable.LoadDataRow Method (Object[], Boolean)

Finds and updates a specific row. If no matching row is found, a new row is created using the given values.

Namespace: System.Data
Assembly: System.Data (in

public DataRow LoadDataRow (
	Object[] values,
	bool fAcceptChanges
public DataRow LoadDataRow (
	Object[] values, 
	boolean fAcceptChanges
public function LoadDataRow (
	values : Object[], 
	fAcceptChanges : boolean
) : DataRow
Not applicable.



An array of values used to create the new row.


true to accept changes; otherwise false.

Return Value

The new DataRow.

Exception typeCondition


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


A value doesn't match its respective column type.


Adding the row invalidates a constraint.


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

The LoadDataRow method takes an array of values and finds the matching value(s) in the primary key column(s).

If a column has a default value, pass a null value in the array to set the default value for that column. Similarly, if a column has its AutoIncrement property set to true, pass a null value in the array to set the automatically generated value for the row.

If the fAcceptChanges parameter is true or not specified, the new data is added and then AcceptChanges is called to accept all changes in the DataTable; if the argument is false, newly added rows are marked as insertions, and changes to existing rows are marked as modifications.

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

Use LoadDataRow in conjunction with BeginLoadData and EndLoadData.

The following example uses the LoadDataRow method to attempt to find a row. If no such row is found, the values are used to create a new row.

private void MyAddUpdate(DataTable table)
    // Create an array for the values.
    object[] newRow = new object[3];

    // Set the values of the array.
    newRow[0] = "Hello";
    newRow[1] = "World";
    newRow[2] = "two";
    DataRow row;

    // Add the new row to the rows collection.
    row = table.LoadDataRow(newRow, true);

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0