Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Best data binding practice: update form or update data row?

$
0
0

Generally, in a form with bound controls, the user enters data into the form controls, then data binding updates the data row, and then code does a table adapter update or something like that, and the updated data row is permanently updated in the database.

Now consider the case where users don't enter data but instead click buttons to set off an action. For example, a work tracking application might have a form for a job task with a button the user clicks to indicate that work has started on this job task. Obviously, the underlying code reacts to the button click and records the DateTime.Now when work has started on the job task. Since the form has a text box that shows when work was started, there are two ways the underlying code can do its thing.

Method 1: The code sets the Text property of the text box to the starting time, and thanks to data binding, this is propagated to the data source's current row. The code then ends edit on the binding source, and issues a table adapter update. Mission accomplished.

Method 2: The code sets the starting time directly in the binding source's current row (SetField or ["field name"] or whatever), end edit, updates that table, and then lets data binding redisplay the row in the form with its updated values.

In other words, do you set values in the form and let data binding update the row, or do you set values in the row and let data binding update the form?

I know it sounds almost like a philosophical question, but perhaps there are good reason to do it one way or the other. What are your thoughts?


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>