Update requires a valid updatecommand when passed datarow collection with modified rows.

·

3 min read

The problem is straightforward: the Adapter requires a proper SQL Update statement. These can be created by dataset designers and CommandBuilders, but there's nothing wrong with manually writing some SQL.

In any case, you'll need to double-check (debug) that the Update statement is still configured and what it is. It might be a SQL issue rather than a C# one.

Image description

Update requires a valid updatecommand when passed datarow collection with modified rows.

This error message may appear while dealing with the database in Visual Studio. When the generic update instructions are called for whatever reason, this message is usually displayed. What is this, exactly? You constructed a SQL server, filled it with tables, and added a table to the form. Some navigation keys on the form will show automatically if you accomplish this by dragging the table from the server. You'll now get this notice if you try to utilize the general update commands like insert, remove, or select. Let's see what's going on here.

Reasons

As expected, this created a DataGridView displaying table that was created. You might be perplexed as to why this notification keeps popping up. However, if you choose the dataset in the Solution Explorer, double-click it to open the design view, and then click on the TableAdapter, you'll notice that those commands are absent in the Properties Window. This is the reason the message keeps appearing. This error will occur if the table does not have a Primary Key as well. It's a more fundamental SQL Server issue, and it's as simple as that.

The Solution

The remedy to this problem isn't to sit down and painstakingly put in the missing commands, as you would imagine. All you have to do now is change the database and make sure at least one column is marked as a Primary Key. This might be the name column in my basic example, but more practically, I'd add an auto-numbering identification column to ensure that all entries in that column are unique. Restart your computer, create a new DataSet, and replace the DataGridView with drag and drop as previously. When you know the solution, it's straightforward; when you don't, it's tremendously aggravating.

So, if you've come here because you're looking at the above message – or anything similar - you've come to the right place.

The Conclusion

The problem is most commonly discovered while using the general Update command (Update commands can be used for Insert, Delete, or Select(Read) depending on the SQLCommand attached).

It's critical, as the error indicates, that the Update function is called by registering a valid UpdateCommand.

It is not a matter of worrying about facing any problem, but of worrying about getting upset in any unpleasant situation. Keep calm and find solutions to your problems. Your comments are always welcome.