none
Update Child Rows with Parent Row ID of Negative Autonumber RRS feed

  • Question

  • Hello All,

    I have two datatables of Teacher and Student. In Teacher table there is a teacherID column of autonumber type as the PK. In Student table there is a studentID column of autonumber type as PK and a teacherID as FK to relate to a teacher.

    When I use typed dataset and add a new teacher, a -1 autonumber is given. Then I added a new student and set its parent as the new added teacher, I also got a autonumber of -1 in teacherID column in Student table.

    Finally I used a adaptermanager's UpdateAll() method to update the database. For the new teacher the teacherID of -1 was converted to a positive value but for the new student, -1 is added to the database in the teacherID column of Student table. Thus the new teacher and new student are not related anymore.

    Does anyone know how to fix this problem?

    Thanks a lot!

    Yi
    Tuesday, February 16, 2010 3:45 PM

All replies

  • Have you added a relationship line into the DataSet designer between the foreign key and primary key field?

    Be sure that cascading update is enabled on that relationship in the designer.

    It typically will automatically work the way you expect when this step is completed.

    Wednesday, February 17, 2010 11:28 PM
  • I did add a relationship and set it as the foreign key and the update rule as cascade, but it did not help.
     
    Thursday, February 18, 2010 2:24 AM