hi! kindly help meeeee :D
Populating the combo box with the list of items from the one of the column in table from database.
Based on the selection of item in the combo box, the another combobox should be populated with value corresponding to the selected item in the first combo box.
Here's my code :
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Form2
Sub fillcombo()
strsql = "select distinct YearLevels from Schedulings"
Dim acscmd = New OleDb.OleDbCommand
acscmd.CommandText = strsql
acscmd.Connection = asconn
acsdr = acscmd.ExecuteReader()
While (acsdr.Read())
ComboBox1.Items.Add(acsdr("YearLevels"))
End While
acscmd.Dispose()
acsdr.Close()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
EnlistmentModule.connect()
Me.fillcombo()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
strsql = "select * from Schedulings where YearLevels = '" & ComboBox1.Text & "'"
Dim acscmd As New OleDb.OleDbCommand
acscmd.CommandText = strsql
acscmd.Connection = asconn
acsdr = acscmd.ExecuteReader()
If acsdr.Read = True Then
ComboBox2.Items.Add(acsdr("Sections"))
End If
ComboBox2.SelectedIndex = -1
acscmd.Dispose()
acsdr.Close()
End Sub
End Class
The problem with this code only the first row that is populate in the 2nd combo box.
help me pls. this is urgent. thank you.