Hi everyone....
I am populating my combo box with data from access database...
what i want to do is...upon clicking a value in the combo box it should display data related to the value selected in a listbox ...how do i do it....
here is the code i am using....
Private Sub Access_to_combo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Open a database connection.
Dim strConnection As String = "Data Source=""D:\INSFORM\Library\Library.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin"
Dim cn As OleDbConnection = New OleDbConnection(strConnection)
cn.Open()
' Set up a data adapter object.
Dim strSql As String = "Select Distinct Publication from Book order by Publication"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSql, cn)
' Load a data set.
Dim ds As DataSet = New DataSet
da.Fill(ds, "Book")
cn.Close()
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "Publication"
End Sub
________________________________________________________________
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim strConnection As String = "Data Source=""D:\INSFORM\Library\Library.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin"
Dim cn As OleDbConnection = New OleDbConnection(strConnection)
Dim selected As String
cn.Open()
' Set up a data adapter object.
Dim strSql As String = "Select Name from Book where Publication = ' " & ComboBox1.Text & " '"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSql, cn)
' Load a data set.
Dim ds As DataSet = New DataSet
da.Fill(ds, "Book")
cn.Close()
ListBox1.DataSource = ds.Tables(0)
ListBox1.DisplayMember = "Name"
End Sub
Will appreciate any feedback...
I am populating my combo box with data from access database...
what i want to do is...upon clicking a value in the combo box it should display data related to the value selected in a listbox ...how do i do it....
here is the code i am using....
Private Sub Access_to_combo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Open a database connection.
Dim strConnection As String = "Data Source=""D:\INSFORM\Library\Library.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin"
Dim cn As OleDbConnection = New OleDbConnection(strConnection)
cn.Open()
' Set up a data adapter object.
Dim strSql As String = "Select Distinct Publication from Book order by Publication"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSql, cn)
' Load a data set.
Dim ds As DataSet = New DataSet
da.Fill(ds, "Book")
cn.Close()
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "Publication"
End Sub
________________________________________________________________
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim strConnection As String = "Data Source=""D:\INSFORM\Library\Library.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin"
Dim cn As OleDbConnection = New OleDbConnection(strConnection)
Dim selected As String
cn.Open()
' Set up a data adapter object.
Dim strSql As String = "Select Name from Book where Publication = ' " & ComboBox1.Text & " '"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSql, cn)
' Load a data set.
Dim ds As DataSet = New DataSet
da.Fill(ds, "Book")
cn.Close()
ListBox1.DataSource = ds.Tables(0)
ListBox1.DisplayMember = "Name"
End Sub
Will appreciate any feedback...