Update requires a valid UpdateCommand when passed DataRow collection

Issue Description

While connecting SQL Server and performing update operation Database gives below error,

System.InvalidOperationException: ‘Update requires a valid UpdateCommand when passed DataRow collection with modified rows.’

Resolution

The issue is mostly found while calling generic Update command( Update commands can be used for Insert, Delete, or Select(Read) depending on the SQLCommand associated.

As the error suggest, It’s important Update method is called by registring the a valid UpdateCommand.

Example:

dataAdpater.UpdateCommand = new SqlCommand(
"UPDATE employee SET LastName = @LastName " +
"WHERE EmployeeID = @EmployeeID", _con);

In the above command, we are defining the UpdateCommand with Update script for Insert or Update or Delete operation.

Please visit below article for reference implementation and guidelines,

Did I miss anything else in these resolution steps?

Did the above steps resolve your issue? Please sound off your comments below!

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *