I have a DataTable with around 500K+ records, and I would like to update a field in the database for each of those records contained in the DataTable.
At the moment, I am getting a list of all the records in the ID column of the DataTable and creating an update statement with an SQL in
statement on those IDs, like so:
string sql = "UPDATE my_table SET my_field = @timestamp WHERE id IN (" + String.Join(", ", myDataTable.AsEnumerable().Select(r => r.Field<Int64>("id")).ToList().ToArray()) + ")";
This works for a few records, however due to the large amount of IDs, I am now getting an error saying that the packet size in MySQL is not large enough for this query.
What can be done, besides increasing the packet size, which seems to be a bad approach?