This topic has not yet been rated - Rate this topic

DataTable.LoadDataRow Method

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

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method LoadDataRow(Object[], Boolean) Finds and updates a specific row. If no matching row is found, a new row is created using the given values.
Public method LoadDataRow(Object[], LoadOption) Finds and updates a specific row. If no matching row is found, a new row is created using the given values.
Top
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Incomplete documentation leads to LoadDataRow confusion, problems
A common problem many users face with use of the LoadDataRow is that the documentation specifies the function will either perform an update of an existing row, or an insert for a new row, but is vague in the semantics of when these occur. In practice, a problem arises when a ConstraintException is thrown when LoadDataRow is used with the intent to perform an update, but an insert is attempted. Because the intent to perform an update implies that the values supplied to LoadDataRow will contain an existing primary key value, the unexpected attempt to perform an insert causes a ConstraintException to be thrown when AcceptChanges is called. The question then becomes how to know and/or control when LoadDataRow updates or inserts.

Many of these problems stem from the documentation here. The documentation for LoadDataRow clearly says to use it in conjunction with BeginDataLoad/EndDataLoad; however, the semantics of coupling these methods implies LoadDataRow is being used for an insert, not an update. The documentation makes no mention of this important distinction.

To use LoadDataRow to perform an update to an existing DataTable row, ensure the call is not encompassed in a BeginDataLoad/EndDataLoad block.