I'm building an app in vs2013 using .net4.5. The app has multiple forms and a local MDF file with multiple tables. I was wondering what best practices are for binding the tables to controls. Should each table/form have it's own databindingsource, should they be combined by form or table?
-
I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Aug 31 '14 at 03:19
2 Answers
These are some binding tutorials that might help you through.
http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial
http://www.developerfusion.com/article/84476/data-binding-for-windows-forms/
http://www.codeproject.com/Articles/18270/A-Guided-Tour-of-WPF-Part-Data-binding
http://forum.codecall.net/topic/49758-basic-data-binding-in-c/

- 14,455
- 21
- 138
- 171
If you are 100% confident that you will not change the data tables (adding, removing, or editing them) then you should have one data context or a way to do CRUD operations per form that will interact with your database. Each form can interact with multiple tables, but just one connection to the database file. You can create local properties and then feed data into them. Each form will need to implement the INotifyPropertyChanged interface. You can also use Entity Framework with MDF, but there are a few extra steps you have to do. In that case you would just bind the entity object to the control.
If you think that you may have to add, remove, or change any tables (on a consistent basis) then you should not bind your data tables directly to the controls in the form. You should instead add a layer between the database and the form. You may want to look into researching MVC or MVVM patterns if that is the case. Hope that helps.

- 31
- 1