Problem using Composite Key...

  • Thread starter Ashwin Murali. T
  • 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...
 
A

Ashwin Murali. T

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...
 
E

Elton Wang

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top