I am trying to create a binding source to my binding navigator that will be able to show all branches within a specific bank.
The statement that gets the datasource is as follows
branchMasterBindingSource.DataSource = Program.Kernel.Get<IBranchMasterService>().GetAllBranchMasters();
However, this pulls all branches regardless of the banks they belong to.
I need to know how to change this so that it gets AllBranchMasters where a field in the database (“U_bank_code”) is equals to a combobox named “cb_bank_code”
Extra code is below:
private void cb_bank_code_SelectedIndexChanged(object sender, EventArgs e)
{
branchMasterBindingSource.DataSource = null;
branchMasterBindingSource.DataSource = Program.Kernel.Get<IBranchMasterService>().GetAllBranchMasters();
//clear textfields after input
lbl_show_bank_name.Text = string.Empty;
txt_branch_code.Text = string.Empty;
txt_branch_name.Text = string.Empty;
txt_swift_sort_code.Text = string.Empty;
txt_address_1.Text = string.Empty;
txt_address_2.Text = string.Empty;
txt_comments.Text = string.Empty;
var bankMasterService = Program.Kernel.Get<IBankMasterService>();
var bankMasters = from bm in bankMasterService.GetAllBankMasters()
where bm.U_Bank_code.Trim().Equals(cb_bank_code.Text.Trim(), StringComparison.CurrentCultureIgnoreCase)
select bm;
if (bankMasters.Any(x => x != null))
{
var bankMaster = bankMasters.First();
lbl_show_bank_name.Text = bankMaster.U_Bank_name;
CbBankCode = bankMaster.U_Bank_code;
}
else
{
//clear textfields after input
lbl_show_bank_name.Text = string.Empty;
}
Im new to C# and dot net and do not know how the syntax to change the statement. Any help appreciated
Although you should look at refactoring your data access methods to do the filtering something like this should do the trick for you