mcerk Posted December 11, 2004 Posted December 11, 2004 Hi I don't know what is wrong here. I allways got this error message: An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll Additional information: This constraint cannot be enabled as not all values have corresponding parent values. Here is my code: OleDbConnection2.ConnectionString = sConnect OleDbDataAdapter1.Fill(Me.DsOpisDM1, "opisDM") Me.daZahtevanaZnanja.Fill(Me.DsOpisDM1, "x_dodatnaZnanja") DsOpisDM1.Relations.Add("relation", DsOpisDM1.Tables("opisDM").Columns("id"), DsOpisDM1.Tables("x_dodatnaZnanja").Columns("id_opisDM")) if I disable last row (DSOpisDM1.Relations.Add ...) then the program runs perfectly OK. Datasets are filled . . . What am I doing wrong. With this relation I want that only specific rows in x_dodatnaZnanja are displayed.... tx matej Quote
Administrators PlausiblyDamp Posted December 11, 2004 Administrators Posted December 11, 2004 If you are creating a relationship between a parent and a child table then all the child entries must have a valid parent. i.e. Every entry found in id_opisDM must have a matching value in id Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
cpopham Posted December 13, 2004 Posted December 13, 2004 Yes as PlausiblyDamp stated. In some databases, you can have rows taht do not contain the foreign key for the other table. This does not violate any referential integrity rules. But if there is an FG there and it is not null, it must match the primary key of the other table. If this is the case, then when you pull the data over with your dataadpter it will error out. You could modify the dataadpter to say soemthing like "SELECT * FROM x_dodatnaZnanja WHERE opisDM.ID = x_dodatnaZnanja.id_opisDM;" My SQL may be a little off there, but you should be able tog et it from there. This method should prevent your error. Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
pendragon Posted December 13, 2004 Posted December 13, 2004 If you have some records that do not have a relationship with the parent then the DataRelationCollection has a createConstraints option, this defaults to true. I think the following will work if this is the problem. DsOpisDM1.Relations.Add("relation", DsOpisDM1.Tables("opisDM").Columns("id"), DsOpisDM1.Tables("x_dodatnaZnanja").Columns("id_opisDM"), false) [/Code] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.