i use VB.NET Visual studio 2008. i have 2 combobox is cbSection and cbTeam. i need databinding between 2 combobox. when i'm select fields from cbSection after that fields on cbTeam must show. Table EmployeeSection | TeamArtist | Designer Product | Store Product | Repair Relation DataArtist >> Designer Product >> Store, Repair assume, i select Product from cbSection (Table Section) after that it's must show 'Store and Repair' on cbTeam (Table Team) Problem:now, i select cbSection 'Product' but Show 'Artist' after that cbTeam is null value. cbSection >> cbTeam 'Product' but show 'Artist' >> NULL value I need On Display OutputcbSection >> cbTeam Product >> Store, Repair this code: Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Configuration
Dim appConn As String = ConfigurationManager.ConnectionStrings("connDB").ToString
Dim Conn As SqlConnection = New SqlConnection(Me.appConn)
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds As New DataSet()
Public Sub showSection()
da = New SqlDataAdapter("SELECT DISTINCT Section From Employee Order By Section", Conn)
da.Fill(ds)
Conn.Close()
cbSection.DataSource = ds.Tables(0)
cbSection.DisplayMember = "Section"
cbSection.ValueMember = "Section"
cbSection.SelectedIndex = -1
End Sub
Private Sub cbSection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSection.SelectedIndexChanged
If cbSection.SelectedIndex > -1 Then
da = New SqlDataAdapter("SELECT DISTINCT Team From Employee WHERE Section='" + cbSection.SelectedValue.ToString() + "'", Conn)
da.Fill(ds)
Conn.Close()
cbTeam.DataSource = ds.Tables(0)
cbTeam.DisplayMember = "Team"
cbTeam.ValueMember = "Team"
End If
End Sub Thanks For you Time.
|