Update ... Where with a DataSet/DataTable

  • Thread starter John M. Collinson
  • Start date
J

John M. Collinson

I am trying to do something that I would expect to be very easy but I am not
having much luck finding the solution.

I have a DataSet containing one data table of potentially 10000's of rows of
data. Using ADO.NET I need to programmatically perform the equivalent of
the following SQL Statement:

UPDATE DataTable1 SET Field1 = 987 WHERE Field2 = 'XYZ';

Is there a way of performing this function directly against the DataSet or
DataTable without iterating through all of the Rows and examining the value
of each field?

Please note that I must perform the updates against the DataTable and not
the original data source.

Any help would be appreciated.

Thanks
John
 
M

Marina

You can use the Select method to get an array of rows matching the WHERE
clause. Then you could iterate through just those rows and set the values
of the other field.

You still have to manually set the value, but at least you don't have to
loop through each one to see if it needs to be updated.
 
J

John M. Collinson

The problem with the solution that you present is that I do not want to
update the array of rows I want the up DataTable itself.

Also, given you solution I would still end up iterating through every row in
the dataset since the combination of updates that I need to perform would
eventually touch every row.

Thanks for your help Marina.

Do others have any different approaches to how they have solved this
problem?

John
 
M

Marina

The array of rows are pointers to the real rows - not copies of them. So you
would be updating the real DataTable.

I don't think there is another way for you to do this, as in the way a SQL
query would.

At this rate, would it be easier to create a temp table in the database (if
not the real one, maybe a temporary access db), dump your data in there, and
then do all the real work.
 

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