How to update foriegn key ? RRS feed

  • Question

  • Hello Experts,

    I want to update a key in a table which is related to the primary of parent table. I thought updating the primary key in the parent table would automatically update the key in the other table. But it is showing error , asking to declare the key of the child table . How can i do that?

    More detailed:

    The first table is UserInformation , it has the primary key ID. The second table is ContactInformation , it has the key UserID which i have related to ID of UserInformation. My motto of doing this was, i wanted to have a field in ContactInformation which should show that this Contact belongs to this User because UserInformation is a table for registered users and ContactInformation is a table for Contacts of those registered users.

    What I have done is , I have related , graphically , the key UserID to ID using sql server studio express. I have a createcontact page for creating a contact for registered users. I haven't included the field UserID anywhere only for i think it would be updated automatically. But as soon as i press the create button , an error shows "Must declare the scalar variable 'UserID' ". PLEASE, TELL ME HOW TO UPDATE THE FIELD UserID? DO I HAVE TO USE SOME SESSION STATE PROPERTY HERE OR WHAT ? 

    Thank You,

    Chaitanya Pandey

    Saturday, May 28, 2011 9:53 AM


All replies