Link to home
Start Free TrialLog in
Avatar of Jzzzz
JzzzzFlag for United States of America

asked on

Many-to-Many DATARELATION :Couldnt' figure it at all

hi,,


I have 4 tables. t1, t2, t3, t4.

t2 and t4 are many to many.

DATAGRID 1:
t1 - parent table - Primarykey (t1-ID)
    - t2 child table -Primary key (t2-id), Foreign Key (t1-ID), column (t3-ID)not unique, and more columns

DATAGRID 2:

t3 - parent table - Primarykey (t3-ID)
    - t4 child table -Primary key (t4-id), Foreign Key (t3-ID) not unique, and more columns

DATAGRID 3 :

 I need to display the corresponding records in t4 for selection of  't2' in datagrid 1..

As u can see the link for the two tables 't2' and 't4'  is  "t3-ID"...


How to do this?
Avatar of NipNFriar_Tuck
NipNFriar_Tuck

One way to do this is to capture the CurrentCellChanged event on DataGrid1 if the CurrentRow is different then previously, then get the t3-id and loop through table 4 getting all records that have a mathcing t3-id and add those records to DataGrid3...
Avatar of Jzzzz

ASKER

pls can u show me in code...what will happen in

mydatagrid_currentcellchanged(sender, e)
{
  //   ? mydatagrid.currenrowIndex ?

   //how to check if current row is different
   // how to get the column field i.e t3-ID
  // how to loop through the table4

 
  // mydatagrid3.bind();
}
ASKER CERTIFIED SOLUTION
Avatar of NipNFriar_Tuck
NipNFriar_Tuck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jzzzz

ASKER


before the 'foreach' statement
i did this

DataTable dt_new = new DataTable();
         
     dt_new  = mydataSet1.t4 ;

and then used that in the 'foreach'

-----  foreach ( DataRow dr in  dt_new ) {  createrows and bindgrid} ------

but its giving me this error
--------------------------------------------------------------------------------------------------------
"foreach statement cannot operate on variables of type 'System.Data.DataTable' because 'System.Data.DataTable' does not contain a definition for 'GetEnumerator', or it is inaccessible"
--------------------------------------------------------------------------------------------------------


and Should  this "private int lastRowIndex = 0;"
 be  "static int lastRowIndex;"


Avatar of Jzzzz

ASKER

oh..

it has to be

foreach ( DataRow dr in  dt_new.Rows)..

---> dt_new.Rows

And when i run the program

it gives an exception : System.Argument exception at the "foreach( DataRow dr in  dt_new.Rows).."

additional information : "this row is already in another table"

Question : WE are trying to get the rows from a different table in the dataset using the DataRow object., when the currentcellchanged event is fired. is that possible?