Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some explanations on updating database through dataset

Status
Not open for further replies.

panadoll

Programmer
Feb 28, 2002
52
SG
Hi,

I encountered this problem which i manage to solve but I need to know the reason why.

I have 3 tables.
Table 1: Batch table
PK: Batch No

Table 2: Invoice Table
PK: Batch No
: Invoice No

Table 3: Detail table
PK: Batch No
: Invoice No
: Line No

These tables all have relationship i.e. Batch -> Invoice -> Detail. These are all in 1 dataset and I have 3 oledataadapter for ea of the table.

They are all binded to the the database with detail table as a datagrid.

when i try to save the 3 tables using 1 getchanges() statement. However, the detail table is not updated into the database using the adaptor.update statement.
e.g

Dim dsChanges As New DataSet
dsChanges = DS_DetailGrid.GetChanges()

Try
If Not dsChanges_Batch Is Nothing Then
If TableName = "INVBATCH" Or TableName = "" Then Database.UpdateDataSet(OleDbAdpt_InvBatch, dsChanges)
If TableName = "INVHEADER" Or TableName = "" Then Database.UpdateDataSet(OleDbAdpt_InvHeader, dsChanges)
If TableName = "INVDETAIL" Or TableName = "" Then Database.UpdateDataSet(OleDBAdpt_InvDetail, dsChanges)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try


in the end, after several tries, I found out that the solution to my problem is to create 3 getchanges() statement and ea of the 3 data adapters updating the dataset. then my detail table is updated into the database.
e.g
Dim dsChanges_Batch As New DataSet
Dim dsChanges_Header As New DataSet
Dim dsChanges_Detail As New DataSet

dsChanges_Batch = DS_DetailGrid.GetChanges()
dsChanges_Header = DS_DetailGrid.GetChanges()
dsChanges_Detail = DS_DetailGrid.GetChanges()

Try
If Not dsChanges_Batch Is Nothing Then
If TableName = "INVBATCH" Or TableName = "" Then Database.UpdateDataSet(OleDbAdpt_InvBatch, dsChanges_Batch)
If TableName = "INVHEADER" Or TableName = "" Then Database.UpdateDataSet(OleDbAdpt_InvHeader, dsChanges_Header)
If TableName = "INVDETAIL" Or TableName = "" Then Database.UpdateDataSet(OleDBAdpt_InvDetail, dsChanges_Detail)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try


Please enlight me on what is the problem and solutions and does having 3 getchanges() statement have any ill effect?

Thanks U!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top