Update Multiple rows in DataTable at once
-
Hello all, Want to know whether can update data in a DataTable with condition? (like where clause in Query) eg. in DataTable1 currently like this
Col1 Col2 Col3
007 a car
007 b book
012 a calendar
012 b pencil
012 c cup
014 a mouse
014 b phone
055 a penbut, in Database '012' is already existed. Thus, I want to update '012' to be '012A' in DataTable and then use SqlBulkCopy to insert data into Database. After update DataTable1 will be as below
Col1 Col2 Col3
007 a car
007 b book
012A a calendar
012A b pencil
012A c cup
014 a mouse
014 b phone
055 a penPlease suggest how to update this without looping through all rows in DataTable1. Thanks and best regards.
-
Hello all, Want to know whether can update data in a DataTable with condition? (like where clause in Query) eg. in DataTable1 currently like this
Col1 Col2 Col3
007 a car
007 b book
012 a calendar
012 b pencil
012 c cup
014 a mouse
014 b phone
055 a penbut, in Database '012' is already existed. Thus, I want to update '012' to be '012A' in DataTable and then use SqlBulkCopy to insert data into Database. After update DataTable1 will be as below
Col1 Col2 Col3
007 a car
007 b book
012A a calendar
012A b pencil
012A c cup
014 a mouse
014 b phone
055 a penPlease suggest how to update this without looping through all rows in DataTable1. Thanks and best regards.
naunt wrote:
Please suggest how to update this without looping through all rows in DataTable1.
There are no methods to update data in a
DataTable
in bulk AFAIK. You could, however, dump your datatable into a temporary table in Sql Server, do the update there, and merge after.Bastard Programmer from Hell :suss: