Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted

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]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...