Hi. I have two datagridviews (master detail). When i double click on a parent row i open a new form with a child datagridview bounded to a relation od the dataset. I'm using ForeignKeyConstraint to delete a parent row and delete automatically child rows. Everything is ok. But if i add a new parent row and double click it i'm able to add new child rows but when updating the dataset i get no error but the child table doesn't get the new rows. If i don't use ForeignKeyConstraint i can add new child rows with no problem but if i delete a parent row, when updating the dataset i get an error because in the dataset are still the child rows. Debugging the application the status of the new child row is "added" but never updates the DB.
code to read data into the dataset:
code to update dataset:
Any ideas?
Thank you
code to read data into the dataset:
VB.NET:
Dim colsPadres(1) As DataColumn
Dim colsHijas(1) As DataColumn
colsPadres(0) = obtenerDetalleArticulos.Tables("TARTICULOS_CLIENTES").Columns("idArticulo")
colsPadres(1) = obtenerDetalleArticulos.Tables("TARTICULOS_CLIENTES").Columns("idCliente")
colsHijas(0) = obtenerDetalleArticulos.Tables("tarticulos_precios_cliente").Columns("idArticulo")
colsHijas(1) = obtenerDetalleArticulos.Tables("tarticulos_precios_cliente").Columns("idCliente")
'relacion en cascada al borrar de los precios para cada articulo.cliente
Dim idKeyRestraint As ForeignKeyConstraint = New ForeignKeyConstraint(colsPadres, colsHijas)
idKeyRestraint.DeleteRule = Rule.Cascade
'idKeyRestraint.UpdateRule = Rule.Cascade
idKeyRestraint.AcceptRejectRule = AcceptRejectRule.Cascade
obtenerDetalleArticulos.Tables("tarticulos_precios_cliente").Constraints.Add(idKeyRestraint)
obtenerDetalleArticulos.Relations.Add("ClientesPrecios", colsPadres, colsHijas)
VB.NET:
''''CHECK ROW STAUTS BEFORE UPDATE PARENT TABLE
For Each dr In dsArticulos.Tables("tarticulos_precios_cliente").Rows
aux = dr.RowState ''STATUS=ADDED
Next
MyBase.SQL = "select * from TARTICULOS_CLIENTES ta where idArticulo=" & idArticulo
command = Nothing
MyBase.InitializeCommand()
'use commandbuilder in the following call
InitializeDataAdapter(True)
dataAdapter.Update(dsArticulos, "TARTICULOS_CLIENTES")
''''CHECK ROW STAUTS AFTER UPDATE PARENT TABLE
For Each dr In dsArticulos.Tables("tarticulos_precios_cliente").Rows
aux = dr.RowState ''STATUS=UNCHANGED . WHY?
Next
'update child table
MyBase.SQL = "select * from tarticulos_precios_cliente ta where idArticulo=" & idArticulo
command = Nothing
MyBase.InitializeCommand()
'use commandbuilder in the following call
InitializeDataAdapter(True)
dataAdapter.Update(dsArticulos, "tarticulos_precios_cliente")
Any ideas?
Thank you
Last edited: