Setting up subtables

  • Thread starter Thread starter Henry Zektser
  • Start date Start date
H

Henry Zektser

Hey all, quick question, whats the proper way to build a subtable? I have
two datasets;
DataSet dsDetails=new DataSet();

then I do;

daParent.Fill(dsDetails); // Fills table Parent
daChild.Fill(dsDetails); // Fills table Child

The parent/child have a one to many relationship on two fields... How would
I set up the subtable relationship so my grid component can pick it up? I
can find all sorts of samples on XML subtables, but cant figure it out for
straight SQL..

Henry
 
Thanks, that helped!
I did the following after filling my datasets;
DataColumn parentCol;
DataColumn childCol;
DataRelation relVoucherNum;
parentCol=dsVendorActivity.Tables["Master"].Columns["Voucher #"];
childCol=dsVendorActivity.Tables["Detail"].Columns["ORCTRNUM"];
relVoucherNum = new DataRelation("VoucherNumber",parentCol,childCol);
dsVendorActivity.Relations.Add(relVoucherNum);

Which for some reason yields the error below on the new DataRelation line...
What does this mean? Is this related to the fact that not all the master
rows have corresponding children?

'column' argument cannot be null. Parameter name: column
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: 'column' argument cannot be
null. Parameter name: column
 
Hi,
I have the same problem
I manage to create the relation between the two tables but since the
parent table is missing one of the primary keys in the child table,
the constraints fails and the relation is not created.

Any help?
Thanks,
Ronnie
 
Henry Zektser said:
Thanks, that helped!
I did the following after filling my datasets;
DataColumn parentCol;
DataColumn childCol;
DataRelation relVoucherNum;
parentCol=dsVendorActivity.Tables["Master"].Columns["Voucher #"];
childCol=dsVendorActivity.Tables["Detail"].Columns["ORCTRNUM"];
relVoucherNum = new DataRelation("VoucherNumber",parentCol,childCol);
dsVendorActivity.Relations.Add(relVoucherNum);

Which for some reason yields the error below on the new DataRelation line...
What does this mean? Is this related to the fact that not all the master
rows have corresponding children?

No, this is related to the fact either that the "Master" table has no
"Voucher #" column, or that the "Detail" table has no "ORCTRNUM" column.
Either parentCol or childCol == null.
 
Back
Top