It sounds like you have some orphaned records in your OrderItems table.
You will need to remove these or you will need to change your last
parameter in the DataRelation constructor to false.
Hope this helps!
Christopher Reed
Application Analyst
Web Development Coordinator
Information Technology
"...efficient operations and utilization of
technology and communications..."
City of Lubbock
creed@m...
"The oxen are slow, but the earth is patient."
>>> mindwalker@i... 2:47:10 AM 2/22/2003 >>>
Suppose I have the following ASP code, which displays a master-detail
view of two tables:
Set rs1 = db.Execute("SELECT * FROM Orders WHERE X=1 AND
Y=2")
' x=1 and y=2 represent any arbitrary filter criteria, just as an
example
' but the important point is that I'm not retrieving *all* orders
only
' a subset
Do Until rs1.EOF
Response.Write "<u>" &
rs1("OrderID") & "</u><br>"
Set rs2 = db.Execute("SELECT * FROM OrderItems WHERE
OrderID=" & rs1("OrderID")
Do Until rs2.EOF
Response.Write rs2("Item") &
"<br>"
rs2.MoveNext
Loop
Set rs2 = Nothing
Response.Write "<br>"
rs1.MoveNext
Loop
Set rs1 = Nothing
how would I do it in ASP.NET (C# preferably, but VB okay too) using
nested DataRepeaters? I have found a few articles that deal with this
issue, such as
http://www.123aspx.com/redir.aspx?res=29338
and
http://www.123aspx.com/redir.aspx?res=29259
but they both rely on creating a DataRelation between two tables
Orders
and OrderItems, which only seems to work when you retrieve *all*
records
from Orders, not just a subset, because otherwise it will result in an
error "This constraint cannot be enabled as not all values have
corresponding parent values." I know there must be a simple way
to get around this, but I can't figure it out. Here is a snippet of my
code:
DataSet
myDataSet = new DataSet();
SqlDataAdapter
myAdapter = new
SqlDataAdapter();
myAdapter.SelectCommand
= myCommand; // myCommand gets a subset of the data in
myAdapter.Fill(myDataSet,
"Orders"); // the orders table matching certain criteria
myAdapter.SelectCommand
= new SqlCommand("GetOrderItems", myConnection);
myAdapter.Fill(myDataSet,
"OrderItems");
//myDataSet.Tables["OrderItems
// We need to define a relationship between the two tables in the
dataset
DataRelation
myRelation = new DataRelation("OrderID",
myDataSet.Tables["Orders"].Columns["OrderID"],
myDataSet.Tables["OrderItems"].Columns["OrderID"],
true);
myDataSet.Relations.Add(myRelation);
this last line is what causes the error mentioned above. How do I
avoid
this error and still achieve the results I'm looking for?