GetChildRows() and DataRelation problem

  • Thread starter Thread starter Claudiu Tomescu
  • Start date Start date
C

Claudiu Tomescu

Hi,

After hours of frustration digging for an answer I decided to post this
message concerning my GetChildRows and DataRelation problem.

What I'm trying to do is to use a DataSet to fetch data from 3 tables and
then using relations to navigate parent-child records.
First I created an XSD file using VS and then I load this schema into my
DataSet using the ReadXmlSchema() method. Note that I DO NOT want to use the
typed DataSet generated automatically by VS.
After loading the schema into the DataSet I fetch data using an DataAdapter.
So far everyting is fine: I'm writing into an XML file the DataSet's tables
content for check; and the DataRelations and primary/foreign key are
correctly created.
Now if I try to navigate the parent's rows and use the GetChildRows() to
retrieve the corresponding child records, the GetChildRows() returns no
data; and believe me I use the correct relation, cause exactly the same code
works with the typed DataSet generated using the same XSD file.

If someone has any ideas where the problem might be, please don't hesitate.

Thank you in advance

Claudiu
 
Hi,

Could you post code to reproduce this problem? I am using relations in a
similar to your way and it works fine
 
Hi Val,
Here it is the code:

SqlConnection conn = new SqlConnection(RelationsDataSet.CONNECTION_STRING);

SqlDataAdapter da = new SqlDataAdapter();

// uspGetMyData is a stored procedure returning three sets of data
// SELECT * FROM authors; SELECT * FROM titles; SELECT * FROM titleauthor
da.SelectCommand = new SqlCommand("uspGetMyData", conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;

// XSD file contains the description of the three tables I use and the relations (file is enclosed as attachment)
DataSet ds = new DataSet();
ds.ReadXmlSchema(AppDomain.CurrentDomain.BaseDirectory + "..\\..\\pubs.xsd");

// table mapping code is removed; basicaly this maps source Table to authors DataSet table, Table1 source table to titles DataSet table and Title2 source table to titleauthors DataSet table

da.Fill(ds);

Console.WriteLine("**** Navigate relations to display authors and corresponding titles");
foreach (DataRow authRow in ds.Tables["authors"].Rows)
{
Console.WriteLine("{0} {1} ({2})", authRow["au_fname"], authRow["au_lname"], authRow["au_id"]);
// fetch the title identificators for the current author
foreach (DataRow taRow in authRow.GetChildRows(ds.Relations["authorstitleauthor"]))
{
Console.WriteLine("\t{0}", taRow.GetParentRow(ds.Relations["titlestitleauthor"])["title"]);
}
}

Regards
Claudiu
 
Back
Top