Hi im new to C# and I have a form with customer data on it. There is a combo box with the customer name and some address fields. When I select the customer name I would like the address field to be automatically updated from the customer table. Can anyone help me with the code for this. Thanks in advance.

Recommended Answers

All 3 Replies

thats normally why you bind the control to the table/query

thats normally why you bind the control to the table/query

This form is used to fill out another table for quoting. The customer table is used as reference to fill out the customer portion of the quote form.

As LizR said, binding is the best approach, however you can manually locate the Customer in the table and populate the address text box.

string custName = combobox.Text;
DataRow[] addressInfo = custData.Select(string.Format("Customer='{0}'",custName));
if(addressInfo.Length > 0)
{
    edStreet.Text = (string)addressInfo[0]["Street"];
    edCity.Text = (string)addressInfo[0]["City"];
    // and so on...
}

Hope this helps,
Jerry

Be a part of the DaniWeb community

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