Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


How databinding between 2 combobox from database


How databinding between 2 combobox from database

Author
Message
ppcvb
ppcvb
Forum God
Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)

Group: Forum Members
Posts: 1, Visits: 3
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 Employee

Section | Team

Artist | Designer

Product | Store

Product | Repair



Relation Data

Artist >> 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 Output



cbSection >> 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. Smile
Edited
11/22/2012 by ppcvb
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search