Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 4 combo boxes naming
C#
comBoxName,
comBoxContact,
comBoxAddress,
comBoxFunction,


I have bind the data of combo box from access DataBase.
Now i want to use SelectedValueChanged event on comBoxName, when i select a name from the list it automatically select the data against the Name contaning in
VB
comBoxContact,
comBoxAddress,
comBoxFunction,
Posted

1 solution

private void combobox_name_SelectedIndexChanged(object sender, EventArgs e)
        {
	    OdbcConnection con = new OdbcConnection(ConnectionString);
	    con.Open();

            combobox_contact.Items.Clear();
	    combobox_address.Items.Clear();
            combobox_function.Items.Clear();

            string SQLQuery = "Select contact, address,function from Information where name='"+combobox_name.Text+"' ";
            
	    OdbcDataAdapter da1 = new OdbcDataAdapter(SQLQuery, con);

            da1.Fill(ds);

            combobox_contact.DataSource = ds.Tables[0];
            combobox_contact.DisplayMember = "Contact";

	    combobox_address.DataSource = ds.Tables[0];
	    combobox_address.DisplayMember = "address";

	    combobox_function.DataSource = ds.Tables[0]; 
            combobox_function.DisplayMember = "function";

	    // if you want to set value member use this code

            combobox_contact.ValueMember = "Contact";
            

        }


I hope this will help you ,REPLY ME............
 
Share this answer
 
v2
Comments
CHill60 23-Nov-13 7:52am    
An improvement to your solution would be to introduce the use of OdbcParameter instead of appending combobox_name.Text to the sql query. See this link for the details http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcparameter(v=vs.110).aspx[^] and this link for why you should do this http://en.wikipedia.org/wiki/SQL_injection
[no name] 23-Nov-13 7:56am    
Will ypu please explain or give me example ?
Instead of odbc ,sql will also be used.
CHill60 23-Nov-13 8:02am    
There's a reasonably good example here http://www.dotnetperls.com/sqlparameter[^] that uses SqlParameter ... the principle is the same with Odbc and OLE
[no name] 24-Nov-13 1:27am    
thank you i got new information ,

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