loading tables with relations to two combobox  
Author Message
equip





PostPosted: .NET Framework Data Access and Storage, loading tables with relations to two combobox Top

I have 2 Tables, Customer and Product they are related with a customer id field. I have a Customer Combo box and Product Combo box. I would when I select a customer the product combo box will be filed with all product of that customer. How can I achieve this



.NET Development5  
 
 
ShEi





PostPosted: .NET Framework Data Access and Storage, loading tables with relations to two combobox Top

try this one out

Dim myConnection As New SqlConnection(<conection string in here>)

myConnection.Open()

Dim myCommand As New SqlCommand("SELECT PRODUCTNAME FROM PRODUCT WHERE CUSTOMER_ID = CUSTOMER.CUSTOMER_ID", myConnection)

myCommand.ExecuteNonQuery()

Dim myAdapter As New SqlDataAdapter(myCommand)

Dim myDataset As New DataSet()

myConnection.Close()

myAdapter.Fill(myDataset)

Dim N As Integer

Dim I As Integer

N = myDataSet.Tables(0).Rows.Count

For I = 0 To N - 1

COMBOPRODUCT.Items.Add(myDataSet.Tables(0).Rows(I).Item(0))

Next

 

 



 
 
iamunmad





PostPosted: .NET Framework Data Access and Storage, loading tables with relations to two combobox Top

Use DataView to bind data with the combobox.

DataSet cscustomerProduct = new DataSet();
dataAdapter1.Fill( csCustomerProduct);
dataAdapter2.Fill (csCustomerProduct );
comboBox1.DataSource = csCustomerProduct.Tables["Customer"];
comboBox1.DisplayMember="Name";
combpBox1.ValueMember = "CustomerID";
DataView dvProduct = csCustomerProduct.Tables["Product"].DefaultView;
comboBox2.DataSource = dvProduct;

comboBox1.SelectedValueChanged += new EventHandler ( comboBox1_SelectedValueChanged );

void comboBox1_SelectedValueChanged( object sender, EventArgs e )

{

dvProduct.Filter = "CustomerID=" + comboBox1.SelectedValue;

}