Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ForeignKeyConstraint requires the child key values to exist in the parent table!

ForeignKeyConstraint requires the child key values to exist in the parent table!

Scheduled Pinned Locked Moved C#
helpdatabasequestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lodeclaw
    wrote on last edited by
    #1

    Is the subject line too long? Probably. I'm experiencing an issue with my dataset that seems to be telling me that the values for a foreign key in my child table does not exist within the parent table. As far as I can see, the value does exist. This happens when I try to fill a datagridview using a tableadapter. If the program throws the exception as normal I get the usual "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." If I use a try/catch around the query it fills the datagridview but gives me a red warning sign that reads "ForeignKeyConstraint [ForeignKey] requires the child key values (value) to exist in the parent table." Has anyone come across this particular issue? Where can I usually find the properties for foreign key contraints? Any help would be hugely appreciated! (I'm using the generic Fill query created for tables in sqlserver.)

    F M 2 Replies Last reply
    0
    • L Lodeclaw

      Is the subject line too long? Probably. I'm experiencing an issue with my dataset that seems to be telling me that the values for a foreign key in my child table does not exist within the parent table. As far as I can see, the value does exist. This happens when I try to fill a datagridview using a tableadapter. If the program throws the exception as normal I get the usual "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." If I use a try/catch around the query it fills the datagridview but gives me a red warning sign that reads "ForeignKeyConstraint [ForeignKey] requires the child key values (value) to exist in the parent table." Has anyone come across this particular issue? Where can I usually find the properties for foreign key contraints? Any help would be hugely appreciated! (I'm using the generic Fill query created for tables in sqlserver.)

      F Offline
      F Offline
      Fayu
      wrote on last edited by
      #2

      Fill the reference table first and then fill the main table. Your error means that the referenfed DataTable does not have data that the maintable is refering to. Post your code and ill see if i can assist you.

      1 Reply Last reply
      0
      • L Lodeclaw

        Is the subject line too long? Probably. I'm experiencing an issue with my dataset that seems to be telling me that the values for a foreign key in my child table does not exist within the parent table. As far as I can see, the value does exist. This happens when I try to fill a datagridview using a tableadapter. If the program throws the exception as normal I get the usual "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." If I use a try/catch around the query it fills the datagridview but gives me a red warning sign that reads "ForeignKeyConstraint [ForeignKey] requires the child key values (value) to exist in the parent table." Has anyone come across this particular issue? Where can I usually find the properties for foreign key contraints? Any help would be hugely appreciated! (I'm using the generic Fill query created for tables in sqlserver.)

        M Offline
        M Offline
        Matt Graham
        wrote on last edited by
        #3

        I came across this error to when I thought the parent value did exist. For me the solution was that I had to make sure that the ParentColumns and ChildColumns for the constraint listed the columns in the same order.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups