asp.net.ph

DataTable.LoadDataRow Method

System.Data Namespace   DataTable Class


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

[ VB ]
Public Function LoadDataRow ( _
   ByVal values ( ) As Object, _
   ByVal fAcceptChanges As Boolean _
) As DataRow

[ C# ]
public DataRow LoadDataRow (
   object [ ] values,
   bool fAcceptChanges
);

[ C++ ]
public: DataRow* LoadDataRow (
   Object* values __gc [ ],
   bool fAcceptChanges
);

[ JScript ]
public function LoadDataRow (
   values : Object [ ],
   fAcceptChanges : Boolean
) : DataRow;

Parameters

values
An array of values used to create the new row.
fAcceptChanges
true to accept changes; otherwise, false.

Return Value

The new DataRow.

Exceptions


Exception Type Condition
ArgumentException Occurs when the array is larger than the number of columns in the table.
InvalidCastException Occurs when a value does not match its respective column type.
ConstraintException Occurs when Adding the row invalidates a constraint.
NoNullAllowedException Occurs when Attempting to put a null in a column where AllowDBNull is false.

Remarks

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 System.Object.Empty in the array to set the default value for that column. Similarly, if a column has its AutoIncrement property set to true, pass the System.Object.Empty in the array to set the automatically generated value for the row.

If fAcceptChanges 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.

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.

Example

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 myTable ) {
   // create an array for the values.
   object [ ] newRow = new object [ 2 ];
   // set the values of the array.
   newRow [ 0 ] = "Hello";
   newRow [ 1 ] = "World";
   newRow [ 2 ] = "two";
   DataRow myRow;
   myTable.BeginLoadData ( );
   // add the new row to the rows collection.
   myRow = myTable.LoadDataRow ( newRow, true );
   myTable.EndLoadData ( );
}
  C# VB

See Also

DataTable Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph