Click here to Skip to main content
13,863,412 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have a form that has a set of textboxes and a datagrid, i've currently setup 2 binding sources and one dataset containing the 2 tables and the relation, the first BS is the master BS, all the textboxes in the form are bound to this BS, the second BS has the Datasource bound to the the First BS and the datamember is set to the relation, the datagrid is bound to this BS.

The select operation works fine, the Update operations work fine as well, the problem comes with saving when adding a new record, the first BS does not save data at all and the child saves the record but the relation field gets saved with -1, obviously that's because the parent is not set at the time of saving so the proper ID field does not get relayed.

What I have tried:

I've tried the Addnewrow method to no avail, i've tried the AcceptChanges, GetChanges etc with no result, the tableadapter.update simply will not save data back to db, no error is presented , i've tried to debug using Onrowupdating and RowUpdated with no result, connection is ok, the table adapter has all the commands ( Insert, update, Delete, Select). i've tried using a tableadaptermanager with no result.

the last thing i just tried was using transactions and still it does not save back to the db.

In short the question would be what's the proper way to setup such scenario: I.E

2 Tables (Orders, OrderDetails)
1 dataset with this 2 tables and a relation on the OrderID field
2 tables adapters one for each table
2 bindingsources : one binding the Orders textboxes and one binding the datagrid for Orders Details.

I know how to do this manually, what i would like to know is how to automate all of this using the bindingsources since that's the whole point and doing it manually would defeat the purpose i'm looking for here.
Posted
Updated 11-Feb-19 7:51am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If you can't update "all 3", then just try "Orders" by itself. If that works, etc.

You show no code. One can only guess at what your problem is.

Details obviously depends on Orders. Orders are not being added. What follows is irrelevant.
   
Comments
threadw 11-Feb-19 12:58pm
   
Thank you Gerry for your response, below i paste the code for save btn i have i did not post code before and just the abstract because code is to big , have a look and tell me if you see anything i might be overlooking the code is as i have it right now which is the latest i was doing trying transactions to no avail.


Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Dim updatecount As Integer
Try
If TxtRecipeName.Text = "" Then
MessageBox("Please Fill-in Product Code field", "Validación")
TxtRecipeName.Focus()
Exit Sub
'ElseIf TxtCreatedBy.Text = "" Then
' MessageBox("Please Fill-in Prodcut Name field", "Validación")
' TxtCreatedBy.Focus()
' Exit Sub
'ElseIf TxtPortionNumber.Text = "" Then
' MessageBox("Please Fill-in Barcode Field", "Validación")
' TxtPortionNumber.Focus()
' Exit Sub
'ElseIf TxtPortionPrice.Text = "" Then
' MessageBox("Please Select category", "Validación")
' TxtPortionPrice.Focus()
' Exit Sub
'ElseIf TxtRecipePrice.Text = "" Then
' MessageBox("Please Select Supplier", "Validación")
' TxtRecipePrice.Focus()
' Exit Sub
' 'ElseIf TxtUnitPrice.Text = "" Then
' ' MessageBox("Please Fill-in unit Price field", "Validación")
' ' TxtUnitPrice.Focus()
' ' Exit Sub
'ElseIf TxtPortionCost.Text = "" Then
' MessageBox("Please Fill-in Stocks On Hand field", "Validación")
' TxtPortionCost.Focus()
' Exit Sub
' 'ElseIf TxtRL.Text = "" Then
' ' MessageBox("Please Fill-in Reorder Level field", "Validación")
' ' TxtRL.Focus()
' 'Exit Sub
End If

If adding = True Then
'ConnDB()
'RecipeDataSet.AcceptChanges()

RecipeBindingSource.EndEdit()
RecipeRelationBindingSource.EndEdit()
Using updateTransaction As System.Transactions.TransactionScope = New System.Transactions.TransactionScope()
DeleteRecipeIngredients()
DeleteRecipe()
AddNewRecipe()
AddNewRecipeIngredients()
updateTransaction.Complete()
RecipeDataSet.AcceptChanges()
End Using
'RecipeRelationBindingSource.EndEdit()
'updatecount = RecipeTableAdapter.Update(RecipeDataSet.Tables("Recipe"))
'RecipeingredientsTableAdapter.Update(RecipeDataSet)
' updatecount = updatecount + RecipeingredientsTableAdapter.Update(RecipeDataSet.RecipeIngredients)
'MessageBox(updatecount.ToString, "prueba")
'RecipeDataSet.AcceptChanges()
'RecipeBindingSource.ResetBindings(False)
' RecipeRelationBindingSource.ResetBindings(False)
FrmMain.ActionInfo.Caption = "Receta Agregada Exitosamente"
DisableAddDeleteIngredients()
'conn.Close()

Else
If RecipeDataSet.HasChanges Then
RecipeBindingSource.EndEdit()
RecipeRelationBindingSource.EndEdit()
updatecount = RecipeTableAdapter.Update(RecipeDataSet.Recipe)
updatecount = updatecount + RecipeingredientsTableAdapter.Update(RecipeDataSet.RecipeIngredients)
RecipeBindingSource.ResetBindings(False)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190214.1 | Last Updated 11 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100