You use SqlDataAdapter to load a DataTable with rows from a Microsoft SQL Server database table. The table includes an identity column that is the primary key. You configure the adapter's InsertCommand to call a stored procedure that adds a new row that includes all table values except the identity column. You configure the adapter's UpdateCommand to call a stored procedure that updates a row based on the primary key column value.

When testing, you find that you can successfully call the adapter's Update method to add new DataTable rows to the database table. However, you find that when you then modify a column in one of these added DataTable rows and attempt to update the database table a second time, an exception is thrown. The exception indicates that the provided primary key column value was not found in the database. You must fix the problem.

What should you do?

 Posted by Rajkatie on 9/30/2012 | Category: ADO.NET Interview questions | Views: 3527 | Points: 40
Select from following answers:
  1. Ensure that the InsertCommand stored procedure returns the generated primary key column value. Update the DataTable row with this value.
  2. Call DataTable.AcceptChanges after calling the SqlDataAdapter.Update to insert new rows.
  3. Set the AutoIncrement property to True for the primary key column.
  4. All Above

Show Correct Answer


Source: MeasureUp.Com | | Alert Moderator 

Comments or Responses

Login to post response