Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET

 
Hi guys
 
I have a crystal report with 3 parameters company,city,lastname
 
I made a form with 3 ComboBoxes
cbCompany take values from company
cbCity from city and ComboBox3 from lastname
 
This is how I fill the ComboBoxes
 
Private Sub fill_city()
        cn = New SqlConnection(strCon)
        cn.Open()
        cm = New SqlCommand("Select distinct City From Staff", cn)
        dr = cm.ExecuteReader
        While dr.Read
            cbCity.Items.Add(dr("City").ToString)
        End While
        cn.Close()
    End Sub
 
    Private Sub fill_company()
        cn = New SqlConnection(strCon)
        cn.Open()
        cm = New SqlCommand("Select distinct Company From Staff", cn)
        dr = cm.ExecuteReader
        While dr.Read
            cbCompany.Items.Add(dr("Company").ToString)
        End While
        cn.Close()
    End Sub
 
The problem is that I want when I choose a value from cbCompany
the cbCity to take values only for this company
 

Thanks in advance
Posted 19-Jan-13 1:40am
jomachi1.5K
Edited 19-Jan-13 1:46am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I am doubt your question is regarding Crystal Report or the form combo box logic?
your combo box should work as cascade combobox.
 
first fill the item to the company combo box cbCompany. then load the city combo when the user select a company. you can load the city combo with cbCompany SelectedIndexChanged event.
 
you have to modify the City combo stored procedure as
 
string selectedCompany= cbCompany.SelectedValue;
cm = New SqlCommand("Select distinct City From Staff Where Company='" + selectedCompany + "'", cn)
 
I'm not much familer with VB.net coding. may be syntax are not correct.
  Permalink  
Comments
jomachi at 19-Jan-13 8:13am
   
Probably the syntax is wrong because now the cbCity don't show any values
Tharaka MTR at 19-Jan-13 8:21am
   
yep, that because I'm not much familiar with VB.NET. but I think you have an idea what I'm explaining here. so, I hope you can resolve this.
 
please add a debug point to string selectedCompany= cbCompany.SelectedValue; place. and check wheter selected value is correctly pass to the sql or not.
jomachi at 19-Jan-13 8:23am
   
Anyway thank you my friend

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



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 19 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100