Hello,
I have a combo box in my form, where I want to populate the list of employee name whose Designation is "Accountant"
I am using three tables a
<< Account_Dept_Table >>
Acc_ID (P.K)
Emp_ID (F.K)
<< Emp_Info_Table >>
Emp_ID (P.K)
Emp_Name
Designation_ID (F.K)
<< Designation_Table >>
Designation_ID (P.K)
Designation
Code:
//As I am using Data Bound wizard in Comb Box Task but not success here the back end code is following:
this.emp_IdComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue",
this.teacher_Information_MasterBindingSource, "Emp_Id", true));
this.emp_IdComboBox.DataSource = this.tableEmployeeInformationBindingSource;
this.emp_IdComboBox.DisplayMember = "emp_name";
this.emp_IdComboBox.Name = "emp_IdComboBox";
this.emp_IdComboBox.ValueMember = "emp_ID";
//and this code is in form back end:
this.table_Employee_InformationTableAdapter.Fill(this.school_DatabaseDataSet_Employee_Information.Table_Employee_Information);
Loading

Hiren SoniRank #694 · 3.5K reputationPosted Dec 26, 2009, 7:31 AM EST
Saqib Malick14 reputationPosted Dec 27, 2009, 8:43 AM EST
By the way,for my knowledge as I am novice in this field, is there is no other way to do solve this kind of problem, please tell me how many ways I can solve this issue.
Really Thanks,
Regards,
Saqib
Sam HobbsRank #107 · 20.5K reputationPosted Dec 27, 2009, 12:35 PM EST
I think it is possible to create a TableAdapter that has SQL that joins tables. You could create relationships among the tables and then just select the fields you need and then the SQL for the join would be created for you. You could use something outside of Visual Studio, such as SQL Server, to create the SQL that you use for a TableAdapter but you can do it using VS too but I am not sure how. I don't know what is in the code that Hiren provided but I assume it has the SQL you can use for a TableAdapter.
Instead of joining tables, I think it is possible to use sub-queries instead of joins to do what you need to do. If that is possible, then you could use that SQL in a TableAdapter.
Hiren SoniRank #694 · 3.5K reputationPosted Dec 27, 2009, 5:32 PM EST
the another way to bind combobox is to that you can fetch data from the database at runtime . Whose designation is accountant. And add those data to combobox. Thats it... Do you required code 4 that... if my answes helped you, then plz accept answer
Saqib Malick14 reputationPosted Dec 27, 2009, 8:46 PM EST
I only do this for getting result.
I have created a VIEW of the tables by using Query Builder to getting the result of Employee whose DESIGNATION IS "accountant" and save it in VIEW with the name "QueryFilterByaccountant", and then create a data set of "QueryFilterByaccount" and save it to "DataSetFilterByTeacher.xsd"
After that in my form I bind comb box to this data set and getting the result.