Batch Updates using Access/OleDb
Hi guys,
I am building a custom news editing application. I have a datagrid with news stories in and do not want to make this datagrid editable.
However, there are two columns of information which it would be useful to update directly in the grid for multiple records.
These are whether to set the news story to "active" by ticking a checkbox, and where the story appears (e.g. top, middle, bottom) on the page, which I want to change using a Drop-Down List Box.
So, each row/record in the datagrid will have a checkbox and list box.
At the moment, when the user clicks the "Update" button, the application checks each row and whether the checkbox or dropdownlist has changed from its original (database) state. If it has, then it updates the database with the new selection.
My question is - what is the best way to update the database?
At the moment, the program cycles through a FOR loop and compares the selected value of the control against the value in the database. If they are different, it puts through an OleDbCommand to update it.
This doesn't seem very efficient, as if you had 20 rows to update, it would require 20 separate updates.
Is there a way of doing a batch update for multiple records in the same table, perhaps using SQL Set notation or similar?
Thanks in advance,
Graham Wilson.
|