Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Cannot Save or Delete related tables
 

Cannot Save or Delete related tables

I have two parent tables and a child table that I'm able to edit but not add or delete records.

Table01 is the parent table of table02. Table01 has the following columns: Table01ID (key), Table01Description

Table02 is the child table of table01 and THE PARENT TABLE OF TABLE03. It has the following columns: Table02ID (key), Table01ID (relates to table01), Date

Table03 is the child table of table02 and has the following columns: Number (key), Table02ID (relates to table02), Table04ID (relates to table04), column04, column05


The form has the binding navigator of table02 and the binding navigator of table03 - this one without the SAVE button - I do not know why.
The form starts with the Date - from table02, and shows the parent table01 data in a combo Box. When I want to add or edit table02, table01 severs as an example of what to do by choosing the right Table01Description in the combo box. This table, table01 is not updated, only table02 and table03.
The form also has a Table03datagridview That shows the records for the Table02ID. First column is Table02ID, second is Table04ID - it is a combo box to choose a record from table04, third column is column04 and fourth column is column05. For each record of table02 there can be two or more different records in table03.

So far I'm able to edit both tables table02 and table03 but when I click the save button, after a deletion or an addition, on the table02bindingnavigator with the Table03TableAdapter.Update(DataSet.Table03), there is no data deleted or saved.

What I'm doing wrong??


  • Moved byMartin Xie - MSFTMSFTWednesday, July 22, 2009 10:15 AMMove it to DataBinding forum for better support. (From:Visual Basic General)
  •  
fmega  Monday, July 20, 2009 9:24 PM

Hi fmega,

These are my replies to your issues:

1. The BindingNavigator of table03 has no save button.

Reply: If we drag a BindingNavigator control from the ToolBox on to the form, it has no save button as default. We need to add save button by ourselves. We can follow this to add buttons to the BindingNavigator: http://msdn.microsoft.com/en-us/library/safa4957(VS.80).aspx.

2. When the save button is clicked, no data is updated.

Reply: We need to call the EndEdit method of the BindingSource to refresh the data source before we update the data. This is an example:

private void headerBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)

{

this.Validate();

this.headerBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.myDBDataSet);

}

Please feel free to tell me if my reply does not help you or you still have problems.

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer byfmega Friday, July 24, 2009 1:56 AM
  •  
Aland Li  Thursday, July 23, 2009 3:10 AM

Hi fmega,

These are my replies to your issues:

1. The BindingNavigator of table03 has no save button.

Reply: If we drag a BindingNavigator control from the ToolBox on to the form, it has no save button as default. We need to add save button by ourselves. We can follow this to add buttons to the BindingNavigator: http://msdn.microsoft.com/en-us/library/safa4957(VS.80).aspx.

2. When the save button is clicked, no data is updated.

Reply: We need to call the EndEdit method of the BindingSource to refresh the data source before we update the data. This is an example:

private void headerBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)

{

this.Validate();

this.headerBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.myDBDataSet);

}

Please feel free to tell me if my reply does not help you or you still have problems.

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer byfmega Friday, July 24, 2009 1:56 AM
  •  
Aland Li  Thursday, July 23, 2009 3:10 AM
Thank you for your answer. It help me a lot.
fmega  Friday, July 24, 2009 1:56 AM
Hi Aland,

Still regarding my project, I hope you can help me, please.

I have to do an Hierarchical update - delete.

First I have to delete all the records of my child table (Transactions) and then delete then record of the parent table (Main Transaction).

I debugged the program and I use a Do Until loop to delete one by one the records of the child table but it's not deleting. I think the error is on the data types...

The is this:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click

Dim mtid, typeid As Integer
Dim mtdate As Date

Dim frm As Confirm
Dim result As DialogResult

mtdate = Me.TransactionDateDateTimePicker.Text() 'The Table data type is date
mtid = Me.txtBoxTransactionID.Text() 'The Table data type is integer
typeid = Me.Transaction_TypesComboBox.SelectedValue() 'The Table data type is integer

frm = New Confirm()
result = frm.ShowDialog()

If result = Windows.Forms.DialogResult.Cancel Then
MessageBox.Show("DELETE CANCELLED...", "MONEY TRACKER", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Do Until Me.TransactionNumberTextBox.Text() = "" 'There is a datagridview but I do not know how to access a cell to compare in this do until
Dim tnumber, taccid As Integer 'that's why I use a textbox
Dim tdebit, tcredit As String


tnumber = Me.TransactionNumberTextBox.Text() 'The Table data type is integer
taccid = Me.AccIDTextBox.Text() 'The Table data type is integer
tdebit = Me.DebitTextBox.Text() 'The Table data type is money
tcredit = Me.CreditTextBox.Text() 'The Table data type is money
Me.Validate()
Me.TransactionsBindingSource.EndEdit()
Me.TransactionsTableAdapter.Delete(tnumber, mtid, taccid, tdebit, tcredit) 'This one is not working and the loop keeps going on and on... I think I
'
need to change one or more data type for this to take effect

BudgetDataSet.AcceptChanges()
Me.TransactionsTableAdapter.Fill(BudgetDataSet.Transactions) 'This is the child table - table Transactions
Loop

Me.Main_TransactionTableAdapter.Delete(mtid, typeid, mtdate) 'This one is working when I don't have any records on the child table - table Transactions
BudgetDataSet.AcceptChanges()
Me.Main_TransactionTableAdapter.Fill(BudgetDataSet.Main_Transaction) 'This is the parent table - table Main_Transaction

MessageBox.Show("TRANSACTION DELETED...", "MONEY TRACKER", MessageBoxButtons.OK, MessageBoxIcon.Information)

End If

End Sub

By the way, isn't there a way of calling the sub BindingnavigatorDeleteItem? What should be the argument? Isn't is easier?

Sorry for too many questions.

I hope you can help me.

Thanks a lot in advance,

Francisco Megale
fmega  Saturday, July 25, 2009 9:16 PM

You can use google to search for other answers

Custom Search

More Threads

• How to add the items from one list box to another
• Datagrid question
• fill a datatable from a dataview
• IList<T> Woes
• How to display specified no.of rows in a datagridview in windows application
• Saving Data After Re-Configuration of DataBase
• Scrolling 2 DataGridViews Simultaneously Using External ScrollBars
• visual c++ to c#
• disappearing DataGrid row
• Databinding a class with DataGridView