Har problem med DataRelation i c#
Det fungerar fint när jag inte har några kriterier i mina sql sökningar som jag sendan relaterar med varandra med DataRelation.
Detta fungerar:
SqlDataAdapter customerAdapter = new SqlDataAdapter("Select idCustomer, CustomerName from Customer WHERE CustomerName LIKE '"+CustName+"%' ORDER by CustomerName", dbConn);
SqlDataAdapter locationAdapter = new SqlDataAdapter("Select * from OfficeLocation", dbConn);
SqlDataAdapter contactAdapter = new SqlDataAdapter("Select * from Contact", dbConn);
SqlDataAdapter ApplicationAdapter = new SqlDataAdapter("Select * from Applications", dbConn);
customerAdapter.Fill(thisDataSet, "Customers");
locationAdapter.Fill(thisDataSet, "Location");
contactAdapter.Fill(thisDataSet, "Contact");
ApplicationAdapter.Fill(thisDataSet, "Application");
DataRelation CustLocRel = dsResult.Relations.Add("CustLoc", dsResult.Tables["Customers"].Columns["idCustomer"], dsResult.Tables["Location"].Columns["idCustomer"]);
DataRelation LocConRel = dsResult.Relations.Add("LocCon", dsResult.Tables["Location"].Columns["idOffice"], dsResult.Tables["Contact"].Columns["idOfficeLocation"]);
DataRelation LocApplRel = dsResult.Relations.Add("LocAppl", dsResult.Tables["Location"].Columns["idOffice"], dsResult.Tables["Application"].Columns["idOfficeLocation"]);
Men om jag lägger till ett kritera i den första SQL frågan
SqlDataAdapter customerAdapter = new SqlDataAdapter("Select idCustomer, CustomerName from Customer ORDER by CustomerName", dbConn);SqlDataAdapter locationAdapter = new SqlDataAdapter("Select * from OfficeLocation", dbConn);
SqlDataAdapter contactAdapter = new SqlDataAdapter("Select * from Contact", dbConn);
SqlDataAdapter ApplicationAdapter = new SqlDataAdapter("Select * from Applications", dbConn);
Så får jag följande felmeddelande:
This constraint cannot be enabled as not all values have corresponding parent values.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This constraint cannot be enabled as not all values have corresponding parent values.
Någon som kan hjälpa mig?