How do I update a datatable

T

Tim Kelley

I need to loop through a datatable and update a particular field. This
seems like it should be fairly easy but it is giving me fits. Here is the
code that I have so far.

foreach (DataRow row in dataTable.Rows)

{

row["fldName"] = "xyz";

dataAdapter.Update(dataTable);


}

When I run this, I get the following error: Update requires a valid
UpdateCommand when passed DataRow collection with modified rows.

Is there another parameter needed to the update?
 
G

Guest

I think you may be confusing "Update a DataTable" with "Update the DATABASE".

When you do this:
row["fldName"] = "xyz";

you are updating the Datatable.

When you do this:

dataAdapter.Update(dataTable);

You want to update the database. In the second case, you need a vaild
connection, and SqlCommands (or OleDb, whatever type of DataAdapter it is)
that can handle the inserts, deletes, and updates of the table rows in your
database.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top