So I have this:

private void GetSuppliersList()
            ds = oDAL.GetSuppliersList();
            cmbSupplier.DataSource = ds.Tables["SuppliersHeader"];
            cmbSupplier.DisplayMember = "SupplierName";
            cmbSupplier.ValueMember = "SupplierID";

And I need to display SupplierAddress from my SQL database into a textbox so I thought I might need to get the ID (Supplier ID) of the SelectedValue (Supplier Name) from my combobox to get its SupplierAddress and display it at the event of SelectedIndexChanged. Thanks in advance!

Recommended Answers

This post might help you.

Jump to Post

All 3 Replies

if cmbSupplier.SelectedIndex = -1 nothing has been selected
otherwise SupplierID is cmbSupplier.SelectedValue

-When your event fires just store the supplier ID into a variable;
-Use that variable in your SQL query for example--> select address from table where id=@some_number. Since every value is unique you will get only one result. After you read the executed query table store your address in a variable or display it in the textbox immediatly. Ofcourse you must open a connection, write the sql query, execute the reader so that you can achieve the desired.
If a problem occures along just post you code here...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.