1st, why use use Validating event? Why not SelectedIndexChnaged (of comboBox(es))?
2nd, change comboBoxX.Text with comboBoxX.SelectedItem.tostring()
3rd, remove "if(rid.HasRows)" out of the code, change it with "if(rid.Read())" statement
and last,:
You cannot use comboBox3.Text, this will do nothing. What you can do, is to ADD a new Item to this comboBox. And then select it (if you want to show it on top (in "textBox" of comboBox area).
So change ComboBox3.Text = rid(2) to: ComboBox3.Items.Add(rid(2).ToString())
--
Hope it helps,
bye
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Ok, I did renovate your code, and it you have data inside your table (and it connection string is the right one), is must work:
Private Sub ComboBox3_SelectedIndexChanged(sender As System.Object, e As System.EventArgs)
con = New OleDbConnection("Provider= Microsoft.ACE.oledb.12.0; Data Source=C:\Users\edenzam\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
Dim ewaaa As String = "SELECT * FROM Schedulings WHERE YearLevels = '" & ComboBox3.SelectedItem.ToString() & "' AND Sections = '" & ComboBox1.SelectedItem.ToString() & "'"
com = New OleDbCommand(ewaaa, con)
con.Open()
rid = com.ExecuteReader()
If rid.Read() Then
Dim text As String = rid(2).ToString()
ComboBox3.Items.Add(text)
'2 means 3rd column! do you have 3 columns inside table?
'show this on top:
ComboBox1.Text = text
'Interaction.MsgBox("Section Already Exist", MsgBoxStyle.Critical, "Error");
ComboBox3.SelectedIndex = -1
' do nothing
Else
End If
End Sub
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Put a break point before this line of code:
Dim text As String = rid(2).ToString()
and you will see by putting a mouse cursor over "text" variable if there is any text iside.
If it is , it code should put text into comboBox, else its something wrong with query statement.
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13