I have created a database with three tables:
1) Users
2) Empoyees
3) History
The history table is related to the employees table through the EmployeeID column in each table, the EmployeeID is the Primary key in the Employees Table, and EmployeeId is the FKey in history table...
The employees table has an fkey column called userid which is a relation the the users table pkey userid
now I in the datasources window I set the UserTable to be a details view and the othe two tables are gridviews. Then I dragged The USerTable to my form and it created the needed components then i dragged the employees table that was under the usertable and the historytable under the employeestable so the realationships were set right!
now when i run the app i have added 3 records and saved them to the database just fine so when i reload the app the records show up properly. i had to add this code to the bindingnavigators save menuItem click event:
now when i click the delete menuItem of the bindingnav control it deletes the row and the related rows from the related tables as desired but if i click save menu item it throws an exception::
The DELETE statement conflicted with the REFERENCE constraint "FK_EmployeeTable_UserTable". The conflict occurred in database "C:\DOCUMENTS AND SETTINGS\RHONDA\MY DOCUMENTS\VISUAL STUDIO 2005\PROJECTS\WAID\WAID\BIN\DEBUG\MYDATA\MYINFORMATION.MDF", table "dbo.EmployeeTable", column UserID.
The statement has been terminated.
How do I commit the changes to the underlying datasource. I dont understand it, cause when I add a new record then enter all the data into the tables and click saveMenuItem it saves fine but not if i delete a record then save it??? Please help! TIA
1) Users
2) Empoyees
3) History
The history table is related to the employees table through the EmployeeID column in each table, the EmployeeID is the Primary key in the Employees Table, and EmployeeId is the FKey in history table...
The employees table has an fkey column called userid which is a relation the the users table pkey userid
now I in the datasources window I set the UserTable to be a details view and the othe two tables are gridviews. Then I dragged The USerTable to my form and it created the needed components then i dragged the employees table that was under the usertable and the historytable under the employeestable so the realationships were set right!
now when i run the app i have added 3 records and saved them to the database just fine so when i reload the app the records show up properly. i had to add this code to the bindingnavigators save menuItem click event:
Code:
this.Validate();
this.userTableBindingSource.EndEdit();
this.employeeTableTableAdapter.Update(this.myInformationDataSet.EmployeeTable);
this.historyTableTableAdapter.Update(this.myInformationDataSet.HistoryTable);
this.userTableTableAdapter.Update(this.myInformationDataSet.UserTable);
now when i click the delete menuItem of the bindingnav control it deletes the row and the related rows from the related tables as desired but if i click save menu item it throws an exception::
The DELETE statement conflicted with the REFERENCE constraint "FK_EmployeeTable_UserTable". The conflict occurred in database "C:\DOCUMENTS AND SETTINGS\RHONDA\MY DOCUMENTS\VISUAL STUDIO 2005\PROJECTS\WAID\WAID\BIN\DEBUG\MYDATA\MYINFORMATION.MDF", table "dbo.EmployeeTable", column UserID.
The statement has been terminated.
How do I commit the changes to the underlying datasource. I dont understand it, cause when I add a new record then enter all the data into the tables and click saveMenuItem it saves fine but not if i delete a record then save it??? Please help! TIA