Parent/Child Database Problems

Joined
Feb 24, 2012
Messages
5
Location
Georgetown, Guyana, Guyana
Programming Experience
Beginner
I am creating an Application Database for my company and I have a main form setup with fields for the parent table and tabs for the child tables. I have the dataset loaded with my 3 tables but whenever I insert new data into the form, the main table alone gets updated and the data is lost from the child forms. I have created relationships between the forms based on the primary key of the main table (this is an auto increment number). I am using SQLServer 2008 and VS2010 Ultimate. It appears that the TableAdapterManager is not updating the necessary tables with the primary key of the main table. I even set an addnew event on the other binding sources of the other tables in order to commit the main table before any of the others but still no luck. Any help would be appreciated!

This is the code where i try to save
Private Sub EmpDataBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmpDataBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.EmpExpBindingSource.EndEdit()
        Me.EmpRefBindingSource.EndEdit()
        Me.EmpSchBindingSource.EndEdit()
        Me.EmpDataBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.CensusApplicationDataSet)
    End Sub
 
Isn't there anyone who can start pointing me in any direction or anyone with some suggestions? Looking forward for the help I am pretty desperate to have this wrapped up as it is the only thing holding me back from completing this mini project!
 
Solved

Ok so I have solved my own problem but for the sake of others having this problem I will outline the solution. I implemented a stored procedure in my data source to return the identity column value of the newly inserted row. So each time the main table has new data inserted the new query is executed and in turn executes the stored procedure. The procedure looks like the following:

VB.NET:
Create Procedure somename
(
     @firstvalue
     @secondvalue
)

AS

INSERT INTO tablename(firstvalue,secondvalue) VALUES(@firstvalue,@secondvalue)
SELECT SCOPE_IdENTITY()

I use select scope_identity at the end of the stored procedure in order to return the identity column value of the data just inserted. The query that is created in my dataset's tableadapter is set to execute scalar. The following is how i recieve my identity value:


VB.NET:
Dim adapter As New DatasetNameTableAdapters.tableadaptername
Dim id AS INTEGER

id = adapter.queryname(firstvalue,secondvalue)


I then used id to fill all my foreign key variables.

Hope I was clear enough and that this will assist someone else looking at this problem.
 
Back
Top