views:

39

answers:

3

I came across this a few times in my career and never really found an answer. My question is in regards to a web form that contains multiple controls that the user can update, and then saves the data to a database (easiest example I can think of right now is a user profile form - see SO profile edit screen).

So far, I have always just saved every control's value to the database. To me, it seems easier to have one method that calls one stored procedure, passing all the page's form values in.

I have seen pages that seem to save the individual control's value, rather than the entire set of controls. It can definitely look nice (if the page is doing it through AJAX), but is it better? I would think you would need more overhead to get this done, like one (or many?) DTO, more methods, and more stored procedures?

Which way is better? And are there any examples of how the individual control way is done?

Thanks!

A: 

I'd generally recommend using the individual control method; it provides for much greater granularity of design.

McWafflestix
A: 

Depends what you mean by better.

"one method, stored procedure" - quicker to code, easier to maintain. "save the individual control's value" - more optimized? I'd leave optimization to last. Looks nicer? Is usability actually a problem on this page? YAGNI - fix performance/usability only if they are broken.

russau
A: 

Some thoughts

  • It's one call to the database whether it's 25 columns or a single column

  • (Similar) If you update 6 controls in one edit session, you do it in one call rather than 6 separate ones

  • You may have forms with dependent or linked controls or disallowed value combinations: The general case would be "multiple control" changes in one edit session: so code for this

  • The general idea of auditing/timestamping is at the unique *row *level, not column.

gbn