I am trying to create a parent/child relationship within two related tables customer and cust_addresses. The tables are linked via customer.o_id = cust_addresses.instance_id
Here is the code to create the relationship between the tables within the dataset
//Fill the dataset's first table with the Customer table
...
string sqlQueryString = "SELECT * FROM ss_customer_t";
SqlConnection myConn = new SqlConnection(connString);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(sqlQueryString, myConn);
// Build the DataSet
ds = new DataSet();
adapter.Fill(ds, "Customer");
//Fill the dataset's second table with the Addresses table
...
string sqlQueryString2 = "SELECT * FROM ss_cust_address_t";
SqlConnection myConn2 = new SqlConnection(connString2);
SqlDataAdapter adapter2 = new SqlDataAdapter();
adapter2.SelectCommand = new SqlCommand(sqlQueryString2, myConn2);
adapter2.Fill(ds, "Addresses");
//Create the relationship between Customer and Addresses
drel = new DataRelation("CustomerAddresses", ds.Tables["Customer"].Columns["o_id"], ds.Tables["Addresses"].Columns["instance_id"]);
ds.Relations.Add(drel);
AND THIS IS HOW I AM TRYING TO ACCESS THE RELATIONSHIP, TO GET THE CHILD ROWS
DataRow[] ChildRows = ds.Tables["Customer"].Rows[rowCtr].GetChildRows("CustomerAddresses");
Unfortunately I keep getting the error message:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Even though there is addresses for each customer
Can anyone help? What am I doing wrong?
Marika
Here is the code to create the relationship between the tables within the dataset
//Fill the dataset's first table with the Customer table
...
string sqlQueryString = "SELECT * FROM ss_customer_t";
SqlConnection myConn = new SqlConnection(connString);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(sqlQueryString, myConn);
// Build the DataSet
ds = new DataSet();
adapter.Fill(ds, "Customer");
//Fill the dataset's second table with the Addresses table
...
string sqlQueryString2 = "SELECT * FROM ss_cust_address_t";
SqlConnection myConn2 = new SqlConnection(connString2);
SqlDataAdapter adapter2 = new SqlDataAdapter();
adapter2.SelectCommand = new SqlCommand(sqlQueryString2, myConn2);
adapter2.Fill(ds, "Addresses");
//Create the relationship between Customer and Addresses
drel = new DataRelation("CustomerAddresses", ds.Tables["Customer"].Columns["o_id"], ds.Tables["Addresses"].Columns["instance_id"]);
ds.Relations.Add(drel);
AND THIS IS HOW I AM TRYING TO ACCESS THE RELATIONSHIP, TO GET THE CHILD ROWS
DataRow[] ChildRows = ds.Tables["Customer"].Rows[rowCtr].GetChildRows("CustomerAddresses");
Unfortunately I keep getting the error message:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Even though there is addresses for each customer
Can anyone help? What am I doing wrong?
Marika