Never forget the primary key (PK) on a table!

Want to kill an hour?  Forget to include a primary key constraint on a SQL table and use the Visual Studio auto-generated dataset.

You will get this error when issuing the Update() command on an adapter:

“Update requires a valid UpdateCommand when passed DataRow collection with modified rows.”

If you look at the code in yourdataset.Designer.cs file for

private void InitAdapter()

it will not include the necessary INSERT INTO, DELETE FROM and UPDATE commands—it will only include the INSERT INTO. Of course it makes sense that MSDataSetGenerator would not know how to generate proper SQL code without a primary key… But all the code behind code makes debugging difficult!

Leave a Reply

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