Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Update Data Using A TableAdapter

$
0
0

I have a relational Database with tables for "App", CoApp' and "Property".  I have from with DataGridViews for each of these tables. I have set up the "Update" function in a Transaction and it works perfectly, for Adding, Deleting and Modifying.  However when I replace on of the DataGridViews with individual controls from exactly the same table, then my "Update" function does not work.  Can someone offer an explanation.  The code I am currently using is as below:

 

Private

Sub TblAppBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblAppBindingNavigatorSaveItem.Click

Me.Validate()

Me.TblAppBindingSource.EndEdit()

Me.TblAppTableAdapter.Update(Me.LTDBDataSet.tblApp)

'Set dims for first Child Table (CoApp)

Dim deletedChildCoApp As LTDBDataSet.tblCoAppDataTable = CType(LTDBDataSet.tblCoApp.GetChanges(Data.DataRowState.Deleted), LTDBDataSet.tblCoAppDataTable)

Dim newChildCoApp As LTDBDataSet.tblCoAppDataTable = CType(LTDBDataSet.tblCoApp.GetChanges(Data.DataRowState.Added), LTDBDataSet.tblCoAppDataTable)

Dim modifiedChildCoApp As LTDBDataSet.tblCoAppDataTable = CType(LTDBDataSet.tblCoApp.GetChanges(Data.DataRowState.Modified), LTDBDataSet.tblCoAppDataTable)

'Set dims for second Child Table (PropBank)

Dim deletedChildPropBank As LTDBDataSet.tblPropBankDataTable = CType(LTDBDataSet.tblPropBank.GetChanges(Data.DataRowState.Deleted), LTDBDataSet.tblPropBankDataTable)

Dim newChildPropBank As LTDBDataSet.tblPropBankDataTable = CType(LTDBDataSet.tblPropBank.GetChanges(Data.DataRowState.Added), LTDBDataSet.tblPropBankDataTable)

Dim modifiedChildPropBank As LTDBDataSet.tblPropBankDataTable = CType(LTDBDataSet.tblPropBank.GetChanges(Data.DataRowState.Modified), LTDBDataSet.tblPropBankDataTable)

'Update First Child Table (CoApp)

Try

If deletedChildCoApp IsNotNothingThen

TblCoAppTableAdapter.Update(deletedChildCoApp)

EndIf

TblAppTableAdapter.Update(LTDBDataSet)

If newChildCoApp IsNotNothingThen

TblCoAppTableAdapter.Update(newChildCoApp)

EndIf

If modifiedChildCoApp IsNotNothingThen

TblCoAppTableAdapter.Update(modifiedChildCoApp)

EndIf

LTDBDataSet.AcceptChanges()

Catch ex As Exception

Finally

If deletedChildCoApp IsNotNothingThen

deletedChildCoApp.Dispose()

EndIf

If newChildCoApp IsNotNothingThen

newChildCoApp.Dispose()

EndIf

If modifiedChildCoApp IsNotNothingThen

modifiedChildCoApp.Dispose()

EndIf

EndTry

'Update Second Child Table (PropBank)

Try

If deletedChildPropBank IsNotNothingThen

TblPropBankTableAdapter.Update(deletedChildPropBank)

EndIf

TblCoAppTableAdapter.Update(LTDBDataSet)

If newChildPropBank IsNotNothingThen

TblPropBankTableAdapter.Update(newChildPropBank)

EndIf

If modifiedChildPropBank IsNotNothingThen

TblPropBankTableAdapter.Update(modifiedChildPropBank)

EndIf

LTDBDataSet.AcceptChanges()

Catch ex As Exception

Finally

If deletedChildPropBank IsNotNothingThen

deletedChildPropBank.Dispose()

EndIf

If newChildPropBank IsNotNothingThen

newChildPropBank.Dispose()

EndIf

If modifiedChildPropBank IsNotNothingThen

modifiedChildPropBank.Dispose()

EndIf

MsgBox(

"DataBase has been successfully updated")

EndTry

 

EndSub

Viewing all articles
Browse latest Browse all 2535

Trending Articles