Last post Oct 23, 2016 11:23 AM by PatriceSc
Oct 23, 2016 12:27 AM|Gleeming|LINK
I have a listbox control which I used to display a list of about 300 people who belong to a certain club. When the web form is loaded the listbox control is loaded
from a sql server table named ClubMembers. In addition to displaying the list of club members in the listbox control, I also allow the application user to either
delete one or more club members from the listbox control, or to add a new club member to the listbox control. The addition occurs when someone types a new club
members name into a textbox and presses an "Insert New Member" button. I also have a "Delete" button which allows for deleting club members from the listbox control.
When the application user has finished adding or deleting club members from the text box control, then can press a save button and then the ClubMembers table willl be updated, adding new club members to the table, and also deleting from the CubMembers table
members who were deleted from the listbox control.
I am storing the listbox club members in a DataTable object, which is also save in a session variable.
So here is my question. In my C# code when I update the sql ClubMembers table, should I use a DataSet object to hold the ClubMembers? And then add and delete from the data set based upon the the values stored in the lisbox control? Because aren't I allowed
to save the entire data set to the database at one time?
Currently my approach involves single inserts and deletes to the ClubMemebers table, instead of one big update using a DataSet.
Oct 23, 2016 11:23 AM|PatriceSc|LINK
For now it seems you are doing that "by hand" with your own code. .NET allows to do that out of the box the same way ie it check the state for each row to delete old rows, add new rows and update changed rows (by sending SQL statementsn, there is nothing
special here, ultimately you have to send SQL statements to update a db). It is based on the SqlDataAdapter class and can be use for a DataSet or for a single DataTable. see
You "should" never do something. See the benefit you get. Here it might simplify your code as you are doing something that is already included in "out of the box" .NET features. So I would likely go for it if it to simplify my app code.
Or unless you have a specific benefit, you could consider to just do each update as the user ask for it. The "load", "edit", "save all" cycle is better suited IMO for editing "documents" (such as Word, Excel etc...). If you edit db data it seems to me users
are used to just have the changes being applied when they ask for it. Once again make sure you do have some benefit for this design. A user could even be surprised to do several changes, close the browser and see his updates were not taken into account because
he didn't push the big final red "now do apply all those changes I asked so far" button.