How to add more than one DataRelation to a Dataset in C #?

0

Is it possible to add more than one DataRelation to a DataSet? I need three columns in separate tables to be related.

    
asked by anonymous 09.01.2016 / 17:45

1 answer

0

I solved it like this:

DataTable parentDtbl = new DataTable();
DataTable childDtbl = new DataTable();    

parentDtbl = RetornarData1();
childDtbl = RetornarData2();

DataSet dtSet = new DataSet();
dtSet.Tables.AddRange(new DataTable[] { parentDtbl, childDtbl });

DataRelation relation = new DataRelation("relation",
                        new DataColumn[] { dtSet.Tables[0].Columns[0], dtSet.Tables[0].Columns[1], dtSet.Tables[0].Columns[2] },
                        new DataColumn[] { dtSet.Tables[1].Columns[0], dtSet.Tables[1].Columns[1], dtSet.Tables[1].Columns[2]}, false);

dtSet.Relations.Add(relation);
    
10.01.2016 / 18:22