LoadDataRow question

  • Thread starter Thread starter Dennis C. Drumm
  • Start date Start date
D

Dennis C. Drumm

The description for DataTable.LoadDataRow says:
Finds and updates a specific row. If no matching row is found, a new row is
created using the given values.

So I would think from that, that I should be able to fill the object[] array
with values that correspond with each column of that row, and if a row in
the table is found with the same value in the PrimaryKey column, then the
row would be updated with the values in the array. But instead, I get the
error:

A first chance exception of type 'System.Data.ConstraintException' occurred
in system.data.dll

Additional information: Failed to enable constraints. One or more rows
contain values violating non-null, unique, or foreign-key constraints.


What have I missed here? Does LoadDataRow update a row's values?

Thanks,

Dennis
 
Dennis,

The exception comes from the fact that the data table that you are
adding the row to requires something to be populated. For example, one
column might require a non-null value, but you are passing null.

You will have to check the constraints and make sure you are passing the
correct values in.

Hope this helps.
 
Thanks Nicholas:

It turns out I needed to Table.AcceptChanges() before the LoadDataRow, then
everthing will work fine.

Dennis

Nicholas Paldino said:
Dennis,

The exception comes from the fact that the data table that you are
adding the row to requires something to be populated. For example, one
column might require a non-null value, but you are passing null.

You will have to check the constraints and make sure you are passing the
correct values in.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dennis C. Drumm said:
The description for DataTable.LoadDataRow says:
Finds and updates a specific row. If no matching row is found, a new row is
created using the given values.

So I would think from that, that I should be able to fill the object[] array
with values that correspond with each column of that row, and if a row in
the table is found with the same value in the PrimaryKey column, then the
row would be updated with the values in the array. But instead, I get the
error:

A first chance exception of type 'System.Data.ConstraintException' occurred
in system.data.dll

Additional information: Failed to enable constraints. One or more rows
contain values violating non-null, unique, or foreign-key constraints.


What have I missed here? Does LoadDataRow update a row's values?

Thanks,

Dennis
 
Back
Top