Click here to Skip to main content
15,032,033 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
I have two tables, tblTerminal and tblDestination, tblTerminal had two Columns ID and Place. tblDestination also had two columns ID and Destinations. Here is the table data of tblTerminal:
ID = 1, 2
Terminal = Iloilo City, Antique
and here is the table data of tblDestination:
ID = 1, 1, 1, 1, 2, 2, 2, 2
Destinations = Molo, Guimbal, Tigbauan, Miag-ao, Guinsangan, Tiolas, San Joaquin, Mojon

What I want is when I choose Iloilo in ComboBox1, ComboBox2 will show Molo, Guimbal, Tigbauan, and Miag-ao. And When I choose Antique in ComboBox1, ComboBox2 will show Guinsangan, Tiolas, San Joaquin, and Mojon.

PLEASE HELP ME IN MY THESIS PROJECT!!

HERE IS MY CODE:


VB
Imports System
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class Form1
    Dim da As SqlDataAdapter
    Dim ds As New DataSet
    Dim binding As Binding
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dr As DataRelation
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Vargas\Documents\Visual Studio 2008\Projects\Trial02\Trial02\dbTial02.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
        Dim sql As String = "SELECT * FROM tblTerminal"
        Dim sql2 As String = "SELECT * FROM tblDestination"
        Dim da As New SqlDataAdapter(sql, cn)
        Dim da2 As New SqlDataAdapter(sql2, cn)
        da.Fill(ds, "tblTerminal")
        da2.Fill(ds, "tblDestination")
        dr = New DataRelation("TermDes", ds.Tables("tblTerminal").Columns("IDTerminalPlace"), ds.Tables("tblDestination").Columns("IDTerminalPlace"), True)
        ds.Relations.Add(dr)
        ComboBox1.DataSource = ds.Tables("tblTerminal")
        ComboBox1.DisplayMember = "TerminalPlace"
        ComboBox1.ValueMember = "IDTerminalPlace"
        ComboBox1.DataBindings.Add("SelectedValue", ds, "tblDestination.IDTerminalPlace")
        ComboBox2.DataSource = ds
        ComboBox2.DisplayMember = "TermDes"
    End Sub
End Class


my problem is that ComboBox2 doesn't show anything. please help me..
Posted

1 solution

Change

VB
ComboBox2.DataSource = ds
ComboBox2.DisplayMember = "TermDes"

to

VB
ComboBox1.DataSource = ds2.Tables("tblDestination")
ComboBox2.DisplayMember = "TermDes"
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900