S
suzy
I have 2 tables in my database (orders, customers). Not all customers have
orders, but all orders have customers.
When I run the following code, the XML that is returned shows a list of all
orders, and the corresponding customers nested within each order (which is
kind of what i want). BUT, it is also returning customers that don't have
an order.
how can i structure my code so only all orders are returned with
corresponding customers, rather than all orders and all customers.
thanks.
DataSet oDataSet = new DataSet("CustomerOrder");
SqlCommand oCmd = new SqlCommand("select * from orders");
oCmd.Connection = oConn;
SqlDataAdapter oAdapter = new SqlDataAdapter(oCmd);
oAdapter.Fill (oDataSet, "Order");
oCmd.CommandText = "select * from customers";
oAdapter.SelectCommand = oCmd;
oAdapter.Fill (oDataSet, "Customer");
DataRelation oRelation = oDataSet.Relations.Add ("OrderCustomer",
oDataSet.Tables["Order"].Columns["CustomerId"],
oDataSet.Tables["Customer"].Columns["CustomerId"],
false);
oRelation.Nested = true;
return oDataSet.GetXml();
orders, but all orders have customers.
When I run the following code, the XML that is returned shows a list of all
orders, and the corresponding customers nested within each order (which is
kind of what i want). BUT, it is also returning customers that don't have
an order.
how can i structure my code so only all orders are returned with
corresponding customers, rather than all orders and all customers.
thanks.
DataSet oDataSet = new DataSet("CustomerOrder");
SqlCommand oCmd = new SqlCommand("select * from orders");
oCmd.Connection = oConn;
SqlDataAdapter oAdapter = new SqlDataAdapter(oCmd);
oAdapter.Fill (oDataSet, "Order");
oCmd.CommandText = "select * from customers";
oAdapter.SelectCommand = oCmd;
oAdapter.Fill (oDataSet, "Customer");
DataRelation oRelation = oDataSet.Relations.Add ("OrderCustomer",
oDataSet.Tables["Order"].Columns["CustomerId"],
oDataSet.Tables["Customer"].Columns["CustomerId"],
false);
oRelation.Nested = true;
return oDataSet.GetXml();