Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
//This code raises an foreign key violation error on the people table.

private void masterTableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.masterTableBindingSource.EndEdit();
            this.peopleBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.clientsDS);

        }
//this code corrects problem, but shouldn't be necessary.

private void peopleDataGridView_Enter(object sender, EventArgs e)
        {
            this.Validate();
            this.masterTableBindingSource.EndEdit();
            this.masterTableTableAdapter.Update(clientsDS.MasterTable);
        }

What am I missing?
Posted
Updated 12-Feb-11 9:14am
v2
Comments
Albin Abel 13-Feb-11 7:29am    
Foreign key violation usually occurs when update a foreign key, but the key actually not present in the primary table. If you need to add like that then should not maintain integrity of table relationship. That is not recommended. You may need to update the master table, if the people table update has a non exist foreign key
pbsjr 13-Feb-11 11:22am    
The c# application is set to relations only. The relationship rule is in SQL Server 2008 R2. According to to Beth Massey, of Microsoft, my first block to code should be all that is needed but I have found this not to be the case in VB 2008 and c# using SQL Server and Jet engines. While the code doesn't show it. What has to happen is the master table must be saved first and then the query refreshed before entering the datagrid.

1 solution

see this link
http://www.mssqltips.com/tip.asp?tip=1692[^] it may help u
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900