Hi everybody >>
Thanks to this forum >>
I need your help please .. My problem in the Combo Box and SQL query ..
I have three comboboxes linked to an Access 2007 database
first one "Department"
second one "Year"
third one "ClassRoom"
in third combobox I need display the classroom of department and year which select in "first comobobox" and "second comobobox"
for example :
I have 3 department
math first year and have classroom1 and classroom 2
Physics second year and have classroom1
History third year and have classroom3 and classroom 4
when user select math from first combobox
and firt year from second combobox then the third combobox must fill classroom1 , classroom2
I know my English is poor but I hope you understand me ... thank you
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.DataSource = GetTable("select DepID,DepName from Department") ComboBox1.DisplayMember = "DepName" ComboBox1.ValueMember = "DepID" ComboBox1.DataSource = GetTable("select YearID,YearName from Year") ComboBox1.DisplayMember = "YearName" ComboBox1.ValueMember = "YearID" End Sub Public Function GetTable(ByVal query As String) As System.Data.DataTable Dim adp As New OleDb.OleDbDataAdapter(query, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\HamakDatabase.mdb") Dim dt As New Data.DataTable adp.Fill(dt) Return dt End Function Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim r As DataRowView = ComboBox1.SelectedItem Dim rr As DataRowView = ComboBox2.SelectedItem If Not IsNothing(r) Then ComboBox3.DataSource = GetTable("select CRID , CRname From ClassRoom Where YearID = " & r("YearID")&" AND DepID ="&rr(DepID)) End If End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged End Sub
my code work but result of query fault
the third combobox display all classroom in the department which selected in first combobox and don't care to year which select in second combobox
I use Visual Basic 2010
Edited 4 Years Ago by george8: n/a