Software Development

[.NET Error] Update requires a valid UpdateCommand when passed DataRow collection with modified rows

This is an error, with which i was dumbfounded for weeks. But the solution is simple after understanding why it's happening
Like
by Jey Geethan | March 06, 2008
[.NET Error] Update requires a valid UpdateCommand when passed DataRow collection with modified rows

This is an error, with which i was dumbfounded for weeks. The problem is simple. I have a DataSet and it automatically generates INSERT command. So i can add rows to the DataSet and update it easily. But whenever i change values in existing rows and update it via TableAdapter, I get this exception "Update requires a valid UpdateCommand when passed DataRow collection with modified rows". I found inside the generated code that only INSERT command is generated. Whatever i try, the DataSet designer would not create an UPDATE command nor a DELETE command for this TableAdapter.

Solution 1:

You can select the TableAdapter and write your own query for the update command in the property dialog box.

But this is not a good idea.

Solution 2: (Better one)

The problem lies within your table design. Check it out again and check whether you have created a primary key for the table. Mostly this will be the case, as I forgot to create one. Now after creating the primary key, you can recreate the DataSets to get the corresponding UPDATE and DELETE statements.

But if you do not want a primary key in your table, you may resort to first solution.


Jey Geethan

Jey Geethan is a poet, author and an entrepreneur.


Related Articles

Why Microservices?
Software Development

Why Microservices?

by Jey Geethan | December 16, 2022
I have a few tidbits about why to use microservices and why it makes sense to create few microservices as a side project and learn from the same
Top 5 Tips for Software Development Managers To Conduct Effective 1 on 1s With Your Reports
Software Development

Top 5 Tips for Software Development Managers To Conduct Effective 1 on 1s With Your Reports

by Jey Geethan | October 05, 2020
Some of the effective tips that can enhance your 1 on 1s with your reports. In 2020, software development is one of the major industries which provides millions of jobs. In fact, if you look at the statistics, this industry is poised to grow even further. According to Slashdata, it's expected to reach 45 million developers by 2030. As a manager, it's your responsibility that 1 on 1s are effective and help your reports. I want to talk about a few of the things that make this process really effective.
Do you want to use your macbook as a lap-heater?
Software Development

Do you want to use your macbook as a lap-heater?

by Jey Geethan | August 28, 2019
How many times have you felt the coldness of a meeting room and wish you had brought a heater into the room. Now you can convert your macbook into a heater
How to get informative, color prompts on Mac Terminal or iTerm2
Software Development

How to get informative, color prompts on Mac Terminal or iTerm2

by Jey Geethan | August 14, 2019
This article talks about how to get color prompts on your terminal and add some informative things like current git branch and distinctive colors for current path, username etc.
Can you have a dinner conversation around Pull Requests?
Software Development

Can you have a dinner conversation around Pull Requests?

by Jey Geethan | July 11, 2019
I believe that writing code is a way of communication and it enables developers understand better than just talking about the concepts or logic in plain english words.