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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Tim Kelley" wrote:
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?