Click here to Skip to main content
15,882,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
there are three combo box controls and based on first combo box value data bind to combo box 2 and based on second combo box 2 value data bind to third combo box..my question is if the combination record has no value for combo box 3 and yet it is displaying value form another record and not changing until it is matched

i haven't known any solution for this problem...
please help me..

What I have tried:

internal void bindcompname()
        {
            cmd = new SqlCommand("select CompName from company",conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataRow dr = dt.NewRow();
            comboscname.DisplayMember = "CompName";
            comboscname.DataSource = dt;
            comboscname.DropDownStyle = ComboBoxStyle.DropDownList;
        }
        private void comboscname_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            cmd = new SqlCommand("select model.ModNum from model inner join company on model.CompName=company.CompName where model.CompName=@cname",conn);
            cmd.Parameters.AddWithValue("@cname",comboscname.Text);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataRow dr = dt.NewRow();
            combosmnumber.DisplayMember = "ModNum";
            combosmnumber.DataSource = dt;
            combosmnumber.DropDownStyle = ComboBoxStyle.DropDownList;
        }
        private void combosmnumber_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            cmd = new SqlCommand("select mobile.IMEINo from mobile inner join model on model.ModId=mobile.ModId inner join company c on c.CompName=mobile.CompName where model.ModNum=@mid and mobile.Status=@sts", conn);
            cmd.Parameters.AddWithValue("@mid", combosmnumber.Text);
            cmd.Parameters.AddWithValue("@sts", "NotSold");
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataRow dr = dt.NewRow();
            combosimeinumber.DisplayMember = "IMEINo";
            combosimeinumber.DataSource = dt;
            combosimeinumber.DropDownStyle = ComboBoxStyle.DropDownList;
        }
Posted
Updated 20-Mar-18 23:02pm
v2
Comments
Suvendu Shekhar Giri 21-Mar-18 2:02am    
Can you show us the relevant code?
sridhar babu 21-Mar-18 2:24am    
--a content has been moved to the question--
Maciej Los 21-Mar-18 4:57am    
And what's wrong with your code?
sridhar babu 21-Mar-18 8:40am    
CompName ModelNo ImeiNo
Nokia Nk109 9009090909
lenevo ln11 0000908898

my data base is like above and if i select nokia company name the the models under nokia has to bind to combo box 2 and when i select model number IMEI no has to bind to combo box 3
my problem is i has a model number in nokia and no IMEI no but when i select that record it is showing the IMEI no of other model other than showing Empty
i hope you understand my problem
please ping me for clarity...
thank you

 
Share this answer
 
Comments
sridhar babu 21-Mar-18 8:41am    
not worked
Maciej Los 21-Mar-18 8:43am    
:laugh:
Quote:
internal void bindcompname()
{
cmd = new SqlCommand("select CompName from company",conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow();
comboscname.DisplayMember = "CompName";
comboscname.DataSource = dt;
comboscname.DropDownStyle = ComboBoxStyle.DropDownList;
}
private void comboscname_SelectedIndexChanged_1(object sender, EventArgs e)
{
cmd = new SqlCommand("select model.ModNum from model inner join company on model.CompName=company.CompName where model.CompName=@cname",conn);
cmd.Parameters.AddWithValue("@cname",comboscname.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow();
combosmnumber.DisplayMember = "ModNum";
combosmnumber.DataSource = dt;
combosmnumber.DropDownStyle = ComboBoxStyle.DropDownList;
}
private void combosmnumber_SelectedIndexChanged_1(object sender, EventArgs e)
{
cmd = new SqlCommand("select mobile.IMEINo from mobile inner join model on model.ModId=mobile.ModId inner join company c on c.CompName=mobile.CompName where model.ModNum=@mid and mobile.Status=@sts", conn);
cmd.Parameters.AddWithValue("@mid", combosmnumber.Text);
cmd.Parameters.AddWithValue("@sts", "NotSold");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow();
combosimeinumber.DisplayMember = "IMEINo";
combosimeinumber.DataSource = dt;
combosimeinumber.DropDownStyle = ComboBoxStyle.DropDownList;
}
 
Share this answer
 
Comments
Maciej Los 21-Mar-18 3:21am    
This is not an answer. Please delete it. To update your question, use "Improve question" widget.

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