Reputation: 1936
I have this form on an application that I created the controls (textboxes) by dragging and dropping an employeemaster datasource onto the the form.
For now, the form works for all my needs for handling employees.
I have created a new field (business name) in my employeemaster table that I want to store the particular business associated with an employee. I now want to set a condition such that the form only loads with employees of a particular business set as a variable.
How do I filter the employee BindingSource to achieve this? Do I have to individually bind each control with a filter through code? I have not found much help on the internet.
Upvotes: 0
Views: 166
Reputation: 1323
Depending on how much data you'll have in your database, you can do 1 of the following;
Either you filter on the datasource:
bsEmployee.DataSource.Filter = "AcolumnName like 'value'";
or you will make a sql query and add that to your TableAdapter, so that you will not load too much data into your application. (To add a parameterzied query go to DataSet designer,right click the TableAdapter you want to modify, and add a query. in the where statement you can write something like this " WHERE (columnName = @VariableName)"
taEmployee.FillByDepartment(datasetName.dataTableName, departmentNameVariable);
Upvotes: 1