Problem using Composite Key...

  • Thread starter Thread starter Ashwin Murali. T
  • Start date Start date
A

Ashwin Murali. T

I have a table called orderdetails which has a composite key. It is made
of OrderID+ItemCode.

The OrderID comes from the Orders table and the ItemCode comes from the
Items table.(Foreign Key Constraints)

I have a winform application where i have a combobox which displays the
OrderID from the Orders table. On selecting any one OrderID from the
combobox, i want the corresponding rows containing the selected OrderID to
be displayed in a datagrid..

How do i do this. When i try using
Dataset.Tables("TableNAme").Rows.Find(OrderID), i get error saying that only
one key was given and the other is missing....

Kindly help me with this.... ASAP

Chao...
Ashwin...
 
Correction in the message....

When i select the orderID from the combobox, i want corresponding rows from
the OrderDetails table containing the orderID from the combobox to be
displayed in the datagrid...

Chao...
Ashwin...
 
Hi Ashwin,

DataTable.Rows.Find method looks up one specific row in
DataTable.Rows. Since there are two PK fields in the
datatable, it requires both of them in the parameter. I
don't think it's for the data source of your datagrid.

You can use DataView to achieve the goal.

In init the datagrid:
DataView dv = ds.Tables(orderdetails).DefaultView;
Datagrid.DataSource = dv; // shows all records in the
datatable

In orderCombobox.SelectedIndexChanged:
dv.RowFilter = "OrderID ='" + orderCombobox.Text
+ "'"; // only shows records with selected OrderID

HTH

Elton Wang
(e-mail address removed)
 
Back
Top