Editing a dataset

dougancil

Well-known member
Joined
Jun 29, 2010
Messages
50
Programming Experience
Beginner
If I have a dataset that I present to a user, how is it possible that I can offer the ability to edit the data within that dataset and then present a messagebox.show back to the user to confirm/deny changes?

I can go into more detail if necessary.

Thank you

Doug
 
Normally I would show the data in a datagrid or a listview and enable an edit button on the form if a record/row is selected, which will either pop open another window to edit the data or enable a groupbox or panel on the form to edit the data. I would provide a "save" or "update" button to push the changes back as well as a way to cancel.
 
Ok so then 2 questions,

1. How do you pop open another window if a record is selected in the datagrid and
2. How do you "post" back to the database with the button. I'm assuming that in the function of the button that it would have an "update" or "insert" statement to the sql table, correct?

Thanks

Doug
 
1. I create a new form & add the controls to it for the fields that the user will be able to edit. I'll overload the ShowDialog function with a parameter to accept the data (a class or a datarow) & I pass the data when the form gets opened.

2. When the form is closed & the Dialog.Cancel was not returned then I simply perform the update on the database, or I set the selected row in the dataset equal to the row from the form & simply call the update on the dataadapter & the update on the DS
 
So then offering the user the ability to edit in the dataset is not the best way? The only two places that this will be possible in my application is for data that is not "mission critical" but also not completely expendable. I'm new to the ShowDialog function so do you have a link on some good tutorial or documentation on it?

Thanks

Doug
 
I tend to do adds & edits in a window or a dedicated area on a form rather than inline with the actual data. I find it to be less confusing and easier to not save changes made (but keep other changes made) but that's just me.

Also, if you know how to use .Show() then you know how to use .ShowDialog() since ShowDialog opens (shows) a window just like .Show() does except that ShowDialog makes the window dominant in that the user has to acknowledge (close) it before the window under it can continue.
 
Back
Top