Search code examples
c#data-bindingcontrolsmdf

DataBindingSource best practices


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?


Solution

  • 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.