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

Hi,

What is the correct command to commit changes made to a row?
I get this exception:
"Update requires a valid UpdateCommand when passed DataRow collection with modified rows"

on the line:
computersTableAdapter.Update(dRowComputers);


Thanks
foreach (DataRow dRowComputers in lSDBDataSet.Computers.Rows)
{
    if (dRowComputers["HID"].ToString() == _HID)
    {
        //Open row for editting
        dRowComputers.BeginEdit();

        //Set changes to existing row
        dRowComputers.SetField("Computer Name", _ComputerName);

        //Save and close row for edit
        dRowComputers.EndEdit();
        computersTableAdapter.Update(dRowComputers);
    }
}

Open in new window

LVL 3
OrenRozenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Reza RadConsultant, TrainerCommented:
did you set updateCommand for your tableAdapter?
OrenRozenAuthor Commented:
how do I do that?
what I'm missing?
Reza RadConsultant, TrainerCommented:
if you set your table adapter by wizard, go on your table adapter again,
right click on it, select CONFIGURE, you will see a window with there commands:
select command
insert command
update command
delete command

you must set update command to a valid statement,


Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Reza RadConsultant, TrainerCommented:
OrenRozenAuthor Commented:
I don't know the SELECT command and in none of my code where I add, delete and locating data, I use the SELECT command.
Do you suggest  that there is no way I can a save the changes made to a row in a table without using the SELECT command? Just the way I'm not using this command to add or delete rows?

If so, I guess I'll have to learn the SELECT command to solve my issue.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Reza RadConsultant, TrainerCommented:
let me simplify this more,
when you create you .xsd file for TableAdapter, you probably wrote a sql command for select data, or maybe you select a table to fetch data from it, am I right? so , we call this SelectCommand, and this means that this command use for select data from db.
now in that tableAdapter, you must set updateCommand, you can add it yourself , or also you can select generate statements for insert,update,delete ... , this will create all statements automatically for you.

if you work more with your table adapter designer you will figure them out easily.


SriVaddadiCommented:
I assume you are passing "select" query as string to the SQLDataAdapter to fetch data from database

Make sure your underlying table in database has a primary key and write the below code.


SqlCommandBuilder commandBldr = new SqlCommandBuilder(computersTableAdapter);
computersTableAdapter.InsertCommand = commandBldr.GetInsertCommand();
computersTableAdapter.UpdateCommand = commandBldr.GetUpdateCommand();
computersTableAdapter.DeleteCommand = commandBldr.GetDeleteCommand();
commandBldr = null;

The block of code must be placed before computersTableAdapter.Fill is caused.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.