Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 508977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:57:47+00:00 2026-05-13T06:57:47+00:00

I have a many-to-many relation in 3 tables: ProgramUserGroup and Feature are the two

  • 0

I have a many-to-many relation in 3 tables: ProgramUserGroup and Feature are the two main tables, and the link between them is LinkFeatureWithProgramUserGroup, where I have Foreign key relations to the two parent tables.

I have a dataset with inserts: I want to add a new row to ProgramUserGroup, and a related (existing) Feature to the LinkFeatureWithProgramUserGroup table.
When Inserting new rows, I’m setting the default id to -1:

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">   <DataSetUserGroup xmlns="http://tempuri.org/DataSetUserGroup.xsd">
<ProgramUserGroup diffgr:id="ProgramUserGroup1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
  <id>-1</id>
  <Name>99999999999</Name>
  <Active>false</Active>
</ProgramUserGroup>
<LinkFeatureWithProgramUserGroup diffgr:id="LinkFeatureWithProgramUserGroup1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
  <id>-1</id>
  <Feature_id>7</Feature_id>
  <ProgramUserGroup_id>-1</ProgramUserGroup_id>
</LinkFeatureWithProgramUserGroup>  </DataSetUserGroup> </diffgr:diffgram>

while I’m updating the tables, I get an error:

“The INSERT statement conflicted with the FOREIGN KEY constraint “FK-LinkFeatu-Progr-7DCDAAA2”. The conflict occurred in database “x”, table “dbo.ProgramUserGroup”, column ‘id’.”

The code for the update is the following:

 DataSetUserGroupTableAdapters.LinkFeatureWithProgramUserGroupTableAdapter lfa = new LinkFeatureWithProgramUserGroupTableAdapter();
 DataSetUserGroupTableAdapters.ProgramUserGroupTableAdapter pug = new ProgramUserGroupTableAdapter();

 pug.Update(dsUserGroup.ProgramUserGroup);
 lfa.Update(dsUserGroup.LinkFeatureWithProgramUserGroup);

if I check the ProgramUserGroup table’s new row’s ID, it has been updated from -1 to @@identity (like 1099), so it’s okay – it inserts the new row.

But In the LinkFeatureWithProgramUserGroup table, the related ProgramUserGroup.ID value is still -1, it was not updated anyhow.

How could I force the update of the link table’s keys as well?
I’ve tried

 pug.Update(dsUserGroup.ProgramUserGroup);
 dsUserGroup.Merge(dsUserGroup.ProgramUserGroup);
 lfa.Update(dsUserGroup.LinkFeatureWithProgramUserGroup);

But didn’t solve the problem 🙁

Thanks,

b.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:57:47+00:00Added an answer on May 13, 2026 at 6:57 am

    Yes, there’s a work-around for this.

    You need to tell your parent table’s table-adapter to refresh the
    data-table after update operation.
    This is how you can do that.

    1. Open the properties of ProgramUserGroupTableAdapter -> Default Select Query -> Advnaced options. and Check the option of Refresh the data table. Save the adapter now. Now when you call update on table-adapter, the data-table will be updated [refreshed] after the update operation and will reflect the latest values from database table. if the primary-key or any coloumn is set to auto-increment, the data-table will have those latest value post recent update.

    2. Now you can Call the update as pug.Update(dsUserGroup.ProgramUserGroup);

    3. Read latest values from the ProgramUserGroup coloumns and assign respective values into the child table before update. This will work exactly the way you want.

    alt text http://ruchitsurati.net/files/tds1.png

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables connected by a foreign key with a one to many
I have two tables and I need to establish a 1-many relation among them,
In my DB I have two relation between two tables : A many to
Lets say I have two tables - child and parent with many-to-one relation. What
I have two tables A and Band the relation between A to B is
I have two tables: Items and Colors. They have a many to many relation.
My DB have two tables - Question and Topic. To implement many-to-many relation, there
Using SQLAlchemy , I have a one to many relation with two tables -
I have 2 tables having many to many relation and hence there is junction
I have 2 tables: First (Cases) Second (Comments) in one to many relation ;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.