Parent - Child relationship (part 2)

A

Andrea Caldarone

Hi all,

so I've my parent - child relationship, that works fine with select, insert
and update. But I've some trouble with the delete, probably I'm missing
something. My delete sub has theese stpes:

1) delete a row from the parent datatable
2) begin a transaction
3) cals the update method of the sqlDataAdapter for the parent datatable
4) cals the update method of the sqlDataAdapter for the child datatable

but at this point I receive an error:

Unhadled exeption "System.Data.DeletedRowInaccessibleException" in
system.windows.forms.dll
additional information: Deleted row information cannot be accessed through
the row.
 
B

Bart Mermuys

Hi,

Andrea Caldarone said:
Hi all,

so I've my parent - child relationship, that works fine with select,
insert and update. But I've some trouble with the delete, probably I'm
missing something. My delete sub has theese stpes:

1) delete a row from the parent datatable
2) begin a transaction
3) cals the update method of the sqlDataAdapter for the parent datatable
4) cals the update method of the sqlDataAdapter for the child datatable

but at this point I receive an error:

Unhadled exeption "System.Data.DeletedRowInaccessibleException" in
system.windows.forms.dll
additional information: Deleted row information cannot be accessed through
the row.

That doesn't sound like an adapter exception ... can you post the entire
code for your delete sub ? And maybe the button handler that invokes it.


HTH,
Greetings
 
A

Andrea Caldarone

That doesn't sound like an adapter exception ... can you post the
entire code for your delete sub ? And maybe the button handler that
invokes it.

HTH,
Greetings

OK,

'*************************************************************************************
This is the Button handler:
'*************************************************************************************

Private Sub cmdDEL_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDEL.Click
If MsgBox("Eliminare l'immobile selezionato?", MsgBoxStyle.Question
+ MsgBoxStyle.YesNo, cnsAPP) = MsgBoxResult.Yes Then
CType(Me.BindingContext(dsMAIN.Tables("Case")).Current,
DataRowView).Row.Delete()
Call Me.SaveCase()
Else
Nind()
End If
End Sub

'*************************************************************************************
This is the SaveCase routine:
'*************************************************************************************

Private Sub SaveCase()

Dim sqlT As SqlTransaction
Dim strERR As String

'PreSave is a routine of mine wich performs some checks against
control's data before invoking the sub
If PreSave() Then
Try
Bm.EndCurrentEdit()

'apro transazione
cntSQL.Open()
sqlT = cntSQL.BeginTransaction

'collego i commad
Call Me.LinkCommand(sqlT)
Call Me.LinkCommand_StatiAvanzamento(sqlT)

'richiamo l'update degli adapter
alHOUSE.Update(dsMAIN, "Case")
aSA.Update(dsMAIN, "StatiAvanzamentoCase")

'commit della transazione
sqlT.Commit()
cntSQL.Close()

'feedback
Call Saved()

Catch ex As SqlException
Call HandleException(dsMAIN.Tables("Case"), ex, sqlT)
End Try
End If

End Sub

This is the LinkCommand Sub:

Private Sub LinkCommand(ByRef sqlT As SqlTransaction)

Dim cmdINS As New SqlCommand
Dim cmdUPD As New SqlCommand
Dim cmdDEL As New SqlCommand

With cmdINS
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "INSERT [Case] " _
& "(" _
& "[UsoCaseID]," _
& "[LivelliID]," _
& "[CorpiID]," _
& "[StatoCasaID]," _
& "[ProgressivoPianoID]," _
& "[NumeroCamereID]," _
& "[PianiID]," _
& "[SUL]," _
& "[Prezzo]," _
& "[Note]" _
& ") " _
& "VALUES " _
&
"(@UCID,@LIID,@COID,@SCID,@PPID,@CMID,@PIID,@MQ,@PRZ,@NOT); " _
& "SET @ID=SCOPE_IDENTITY()"

'Definizione parametri
.Parameters.Add("@UCID", SqlDbType.Int, 4, "UsoCaseID")
.Parameters.Add("@LIID", SqlDbType.Int, 4, "LivelliID")
.Parameters.Add("@COID", SqlDbType.Int, 4, "CorpiID")
.Parameters.Add("@SCID", SqlDbType.Int, 4, "StatoCasaID")
.Parameters.Add("@PPID", SqlDbType.Int, 2, "ProgressivoPianoID")
.Parameters.Add("@CMID", SqlDbType.Int, 4, "NumeroCamereID")
.Parameters.Add("@PIID", SqlDbType.Int, 2, "PianiID")
.Parameters.Add("@MQ", SqlDbType.Decimal, 5, "SUL")
.Parameters.Add("@PRZ", SqlDbType.Money, 8, "Prezzo")
.Parameters.Add("@NOT", SqlDbType.NText, Me.txtNote.Text.Length,
"Note")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
.Parameters("@ID").Direction = ParameterDirection.InputOutput
.UpdatedRowSource = UpdateRowSource.Both
End With

With cmdUPD
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "UPDATE " _
& "[Case] " _
& "SET " _
& "[UsoCaseID]=@UCID," _
& "[LivelliID]=@LIID," _
& "[CorpiID]=@COID," _
& "[StatoCasaID]=@SCID," _
& "[ProgressivoPianoID]=@PPID," _
& "[NumeroCamereID]=@CMID," _
& "[PianiID]=@PIID," _
& "[SUL]=@MQ," _
& "[Prezzo]=@PRZ," _
& "[Note]=@NOT " _
& "WHERE " _
& "[ID]=@ID"

'Definizione parametri
.Parameters.Add("@UCID", SqlDbType.Int, 4, "UsoCaseID")
.Parameters.Add("@LIID", SqlDbType.Int, 4, "LivelliID")
.Parameters.Add("@COID", SqlDbType.Int, 4, "CorpiID")
.Parameters.Add("@SCID", SqlDbType.Int, 4, "StatoCasaID")
.Parameters.Add("@PPID", SqlDbType.Int, 2, "ProgressivoPianoID")
.Parameters.Add("@CMID", SqlDbType.Int, 4, "NumeroCamereID")
.Parameters.Add("@PIID", SqlDbType.Int, 2, "PianiID")
.Parameters.Add("@MQ", SqlDbType.Decimal, 5, "SUL")
.Parameters.Add("@PRZ", SqlDbType.Money, 8, "Prezzo")
.Parameters.Add("@NOT", SqlDbType.NText, Me.txtNote.Text.Length,
"Note")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With cmdDEL
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "DELETE [Case] WHERE [ID]=@ID"
.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

'cassocio all'adapter
With alHOUSE
.InsertCommand = cmdINS
.UpdateCommand = cmdUPD
.DeleteCommand = cmdDEL
End With
End Sub

'*************************************************************************************
and this is the LinkCommand_StatiAvanzamento sub:
'*************************************************************************************

Private Sub LinkCommand_StatiAvanzamento(ByRef sqlT As SqlTransaction)

Dim cmdUPD As New SqlCommand
Dim cmdINS As New SqlCommand
Dim cmdDEL As New SqlCommand

With cmdINS
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "INSERT " _
& "[StatiAvanzamentoCase] " _
&
"([StatiAvanzamentoID],[CaseID],[Imponibile]) " _
& "VALUES " _
& "(@SID,@CID,@IMP); SET
@ID=SCOPE_IDENTITY()"

.Parameters.Add("@SID", SqlDbType.Int, 4, "StatiAvanzamentoID")
.Parameters.Add("@CID", SqlDbType.Int, 4, "CaseID")
.Parameters.Add("@IMP", SqlDbType.Money, 8, "Imponibile")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
.Parameters("@ID").Direction = ParameterDirection.InputOutput
.UpdatedRowSource = UpdateRowSource.Both
End With

With cmdUPD
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "UPDATE [StatiAvanzamentoCase] SET " _
& "[Imponibile]=@IMP " _
& "WHERE [ID]=@ID"

.Parameters.Add("@IMP", SqlDbType.Money, 8, "Imponibile")
.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With cmdDEL
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "DELETE [StatiAvanzamentoCase] WHERE [ID]=@ID"

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With aSA
.InsertCommand = cmdINS
.UpdateCommand = cmdUPD
.DeleteCommand = cmdDEL
End With
End Sub
 
B

Bart Mermuys

Hi,


Thanks for posting the code, but i can't reproduce the problem with a
similar setup.

Can you tell me what line is throwing this Exception ? And are you
accessing the deleted row inside PreSave ?

HTH,
Greetings

HTH,
Greetings

OK,

'*************************************************************************************
This is the Button handler:
'*************************************************************************************

Private Sub cmdDEL_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDEL.Click
If MsgBox("Eliminare l'immobile selezionato?", MsgBoxStyle.Question
+ MsgBoxStyle.YesNo, cnsAPP) = MsgBoxResult.Yes Then
CType(Me.BindingContext(dsMAIN.Tables("Case")).Current,
DataRowView).Row.Delete()
Call Me.SaveCase()
Else
Nind()
End If
End Sub

'*************************************************************************************
This is the SaveCase routine:
'*************************************************************************************

Private Sub SaveCase()

Dim sqlT As SqlTransaction
Dim strERR As String

'PreSave is a routine of mine wich performs some checks against
control's data before invoking the sub
If PreSave() Then
Try
Bm.EndCurrentEdit()

'apro transazione
cntSQL.Open()
sqlT = cntSQL.BeginTransaction

'collego i commad
Call Me.LinkCommand(sqlT)
Call Me.LinkCommand_StatiAvanzamento(sqlT)

'richiamo l'update degli adapter
alHOUSE.Update(dsMAIN, "Case")
aSA.Update(dsMAIN, "StatiAvanzamentoCase")

'commit della transazione
sqlT.Commit()
cntSQL.Close()

'feedback
Call Saved()

Catch ex As SqlException
Call HandleException(dsMAIN.Tables("Case"), ex, sqlT)
End Try
End If

End Sub

This is the LinkCommand Sub:

Private Sub LinkCommand(ByRef sqlT As SqlTransaction)

Dim cmdINS As New SqlCommand
Dim cmdUPD As New SqlCommand
Dim cmdDEL As New SqlCommand

With cmdINS
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "INSERT [Case] " _
& "(" _
& "[UsoCaseID]," _
& "[LivelliID]," _
& "[CorpiID]," _
& "[StatoCasaID]," _
& "[ProgressivoPianoID]," _
& "[NumeroCamereID]," _
& "[PianiID]," _
& "[SUL]," _
& "[Prezzo]," _
& "[Note]" _
& ") " _
& "VALUES " _
&
"(@UCID,@LIID,@COID,@SCID,@PPID,@CMID,@PIID,@MQ,@PRZ,@NOT); " _
& "SET @ID=SCOPE_IDENTITY()"

'Definizione parametri
.Parameters.Add("@UCID", SqlDbType.Int, 4, "UsoCaseID")
.Parameters.Add("@LIID", SqlDbType.Int, 4, "LivelliID")
.Parameters.Add("@COID", SqlDbType.Int, 4, "CorpiID")
.Parameters.Add("@SCID", SqlDbType.Int, 4, "StatoCasaID")
.Parameters.Add("@PPID", SqlDbType.Int, 2,
"ProgressivoPianoID")
.Parameters.Add("@CMID", SqlDbType.Int, 4, "NumeroCamereID")
.Parameters.Add("@PIID", SqlDbType.Int, 2, "PianiID")
.Parameters.Add("@MQ", SqlDbType.Decimal, 5, "SUL")
.Parameters.Add("@PRZ", SqlDbType.Money, 8, "Prezzo")
.Parameters.Add("@NOT", SqlDbType.NText,
Me.txtNote.Text.Length, "Note")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
.Parameters("@ID").Direction = ParameterDirection.InputOutput
.UpdatedRowSource = UpdateRowSource.Both
End With

With cmdUPD
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "UPDATE " _
& "[Case] " _
& "SET " _
& "[UsoCaseID]=@UCID," _
& "[LivelliID]=@LIID," _
& "[CorpiID]=@COID," _
& "[StatoCasaID]=@SCID," _
& "[ProgressivoPianoID]=@PPID," _
& "[NumeroCamereID]=@CMID," _
& "[PianiID]=@PIID," _
& "[SUL]=@MQ," _
& "[Prezzo]=@PRZ," _
& "[Note]=@NOT " _
& "WHERE " _
& "[ID]=@ID"

'Definizione parametri
.Parameters.Add("@UCID", SqlDbType.Int, 4, "UsoCaseID")
.Parameters.Add("@LIID", SqlDbType.Int, 4, "LivelliID")
.Parameters.Add("@COID", SqlDbType.Int, 4, "CorpiID")
.Parameters.Add("@SCID", SqlDbType.Int, 4, "StatoCasaID")
.Parameters.Add("@PPID", SqlDbType.Int, 2,
"ProgressivoPianoID")
.Parameters.Add("@CMID", SqlDbType.Int, 4, "NumeroCamereID")
.Parameters.Add("@PIID", SqlDbType.Int, 2, "PianiID")
.Parameters.Add("@MQ", SqlDbType.Decimal, 5, "SUL")
.Parameters.Add("@PRZ", SqlDbType.Money, 8, "Prezzo")
.Parameters.Add("@NOT", SqlDbType.NText,
Me.txtNote.Text.Length, "Note")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With cmdDEL
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "DELETE [Case] WHERE [ID]=@ID"
.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

'cassocio all'adapter
With alHOUSE
.InsertCommand = cmdINS
.UpdateCommand = cmdUPD
.DeleteCommand = cmdDEL
End With
End Sub

'*************************************************************************************
and this is the LinkCommand_StatiAvanzamento sub:
'*************************************************************************************

Private Sub LinkCommand_StatiAvanzamento(ByRef sqlT As SqlTransaction)

Dim cmdUPD As New SqlCommand
Dim cmdINS As New SqlCommand
Dim cmdDEL As New SqlCommand

With cmdINS
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "INSERT " _
& "[StatiAvanzamentoCase] " _
&
"([StatiAvanzamentoID],[CaseID],[Imponibile]) " _
& "VALUES " _
& "(@SID,@CID,@IMP); SET
@ID=SCOPE_IDENTITY()"

.Parameters.Add("@SID", SqlDbType.Int, 4, "StatiAvanzamentoID")
.Parameters.Add("@CID", SqlDbType.Int, 4, "CaseID")
.Parameters.Add("@IMP", SqlDbType.Money, 8, "Imponibile")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
.Parameters("@ID").Direction = ParameterDirection.InputOutput
.UpdatedRowSource = UpdateRowSource.Both
End With

With cmdUPD
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "UPDATE [StatiAvanzamentoCase] SET " _
& "[Imponibile]=@IMP " _
& "WHERE [ID]=@ID"

.Parameters.Add("@IMP", SqlDbType.Money, 8, "Imponibile")
.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With cmdDEL
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "DELETE [StatiAvanzamentoCase] WHERE [ID]=@ID"

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With aSA
.InsertCommand = cmdINS
.UpdateCommand = cmdUPD
.DeleteCommand = cmdDEL
End With
End Sub
 
M

Marina Levit [MVP]

Does PreSave try to access the row that was just marked for deletion? If so,
then that is the problem.

You should really identify the actual line in the source code throwing the
exception, that would keep guessing to a minimum. The error is necessary,
but the actual line of code is just as needed - and you should already know
what that is since you have the debugger right there.

Andrea Caldarone said:
That doesn't sound like an adapter exception ... can you post the
entire code for your delete sub ? And maybe the button handler that
invokes it.

HTH,
Greetings

OK,

'*************************************************************************************
This is the Button handler:
'*************************************************************************************

Private Sub cmdDEL_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDEL.Click
If MsgBox("Eliminare l'immobile selezionato?", MsgBoxStyle.Question
+ MsgBoxStyle.YesNo, cnsAPP) = MsgBoxResult.Yes Then
CType(Me.BindingContext(dsMAIN.Tables("Case")).Current,
DataRowView).Row.Delete()
Call Me.SaveCase()
Else
Nind()
End If
End Sub

'*************************************************************************************
This is the SaveCase routine:
'*************************************************************************************

Private Sub SaveCase()

Dim sqlT As SqlTransaction
Dim strERR As String

'PreSave is a routine of mine wich performs some checks against
control's data before invoking the sub
If PreSave() Then
Try
Bm.EndCurrentEdit()

'apro transazione
cntSQL.Open()
sqlT = cntSQL.BeginTransaction

'collego i commad
Call Me.LinkCommand(sqlT)
Call Me.LinkCommand_StatiAvanzamento(sqlT)

'richiamo l'update degli adapter
alHOUSE.Update(dsMAIN, "Case")
aSA.Update(dsMAIN, "StatiAvanzamentoCase")

'commit della transazione
sqlT.Commit()
cntSQL.Close()

'feedback
Call Saved()

Catch ex As SqlException
Call HandleException(dsMAIN.Tables("Case"), ex, sqlT)
End Try
End If

End Sub

This is the LinkCommand Sub:

Private Sub LinkCommand(ByRef sqlT As SqlTransaction)

Dim cmdINS As New SqlCommand
Dim cmdUPD As New SqlCommand
Dim cmdDEL As New SqlCommand

With cmdINS
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "INSERT [Case] " _
& "(" _
& "[UsoCaseID]," _
& "[LivelliID]," _
& "[CorpiID]," _
& "[StatoCasaID]," _
& "[ProgressivoPianoID]," _
& "[NumeroCamereID]," _
& "[PianiID]," _
& "[SUL]," _
& "[Prezzo]," _
& "[Note]" _
& ") " _
& "VALUES " _
&
"(@UCID,@LIID,@COID,@SCID,@PPID,@CMID,@PIID,@MQ,@PRZ,@NOT); " _
& "SET @ID=SCOPE_IDENTITY()"

'Definizione parametri
.Parameters.Add("@UCID", SqlDbType.Int, 4, "UsoCaseID")
.Parameters.Add("@LIID", SqlDbType.Int, 4, "LivelliID")
.Parameters.Add("@COID", SqlDbType.Int, 4, "CorpiID")
.Parameters.Add("@SCID", SqlDbType.Int, 4, "StatoCasaID")
.Parameters.Add("@PPID", SqlDbType.Int, 2,
"ProgressivoPianoID")
.Parameters.Add("@CMID", SqlDbType.Int, 4, "NumeroCamereID")
.Parameters.Add("@PIID", SqlDbType.Int, 2, "PianiID")
.Parameters.Add("@MQ", SqlDbType.Decimal, 5, "SUL")
.Parameters.Add("@PRZ", SqlDbType.Money, 8, "Prezzo")
.Parameters.Add("@NOT", SqlDbType.NText,
Me.txtNote.Text.Length, "Note")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
.Parameters("@ID").Direction = ParameterDirection.InputOutput
.UpdatedRowSource = UpdateRowSource.Both
End With

With cmdUPD
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "UPDATE " _
& "[Case] " _
& "SET " _
& "[UsoCaseID]=@UCID," _
& "[LivelliID]=@LIID," _
& "[CorpiID]=@COID," _
& "[StatoCasaID]=@SCID," _
& "[ProgressivoPianoID]=@PPID," _
& "[NumeroCamereID]=@CMID," _
& "[PianiID]=@PIID," _
& "[SUL]=@MQ," _
& "[Prezzo]=@PRZ," _
& "[Note]=@NOT " _
& "WHERE " _
& "[ID]=@ID"

'Definizione parametri
.Parameters.Add("@UCID", SqlDbType.Int, 4, "UsoCaseID")
.Parameters.Add("@LIID", SqlDbType.Int, 4, "LivelliID")
.Parameters.Add("@COID", SqlDbType.Int, 4, "CorpiID")
.Parameters.Add("@SCID", SqlDbType.Int, 4, "StatoCasaID")
.Parameters.Add("@PPID", SqlDbType.Int, 2,
"ProgressivoPianoID")
.Parameters.Add("@CMID", SqlDbType.Int, 4, "NumeroCamereID")
.Parameters.Add("@PIID", SqlDbType.Int, 2, "PianiID")
.Parameters.Add("@MQ", SqlDbType.Decimal, 5, "SUL")
.Parameters.Add("@PRZ", SqlDbType.Money, 8, "Prezzo")
.Parameters.Add("@NOT", SqlDbType.NText,
Me.txtNote.Text.Length, "Note")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With cmdDEL
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "DELETE [Case] WHERE [ID]=@ID"
.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

'cassocio all'adapter
With alHOUSE
.InsertCommand = cmdINS
.UpdateCommand = cmdUPD
.DeleteCommand = cmdDEL
End With
End Sub

'*************************************************************************************
and this is the LinkCommand_StatiAvanzamento sub:
'*************************************************************************************

Private Sub LinkCommand_StatiAvanzamento(ByRef sqlT As SqlTransaction)

Dim cmdUPD As New SqlCommand
Dim cmdINS As New SqlCommand
Dim cmdDEL As New SqlCommand

With cmdINS
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "INSERT " _
& "[StatiAvanzamentoCase] " _
&
"([StatiAvanzamentoID],[CaseID],[Imponibile]) " _
& "VALUES " _
& "(@SID,@CID,@IMP); SET
@ID=SCOPE_IDENTITY()"

.Parameters.Add("@SID", SqlDbType.Int, 4, "StatiAvanzamentoID")
.Parameters.Add("@CID", SqlDbType.Int, 4, "CaseID")
.Parameters.Add("@IMP", SqlDbType.Money, 8, "Imponibile")

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
.Parameters("@ID").Direction = ParameterDirection.InputOutput
.UpdatedRowSource = UpdateRowSource.Both
End With

With cmdUPD
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "UPDATE [StatiAvanzamentoCase] SET " _
& "[Imponibile]=@IMP " _
& "WHERE [ID]=@ID"

.Parameters.Add("@IMP", SqlDbType.Money, 8, "Imponibile")
.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With cmdDEL
.Connection = cntSQL
.CommandType = CommandType.Text
.Transaction = sqlT
.CommandText = "DELETE [StatiAvanzamentoCase] WHERE [ID]=@ID"

.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
End With

With aSA
.InsertCommand = cmdINS
.UpdateCommand = cmdUPD
.DeleteCommand = cmdDEL
End With
End Sub
 
A

Andrea Caldarone

Hi,

and thanks for your help, I've finally found the mistake I've made:

When I delete the parent record I use this code:

CType(Me.BindingContext(dsMAIN.Tables("Case")).Current,
DataRowView).Row.Delete()

but it's wrong! I use the DeafultView of dsMAIN.Tables("Case") as DataSource
of the parent grid! so the correct line to delete the row is:

CType(Me.BindingContext(dsMAIN.Tables("Case").DefaultView).Current,
DataRowView).Row.Delete()

now it works fine!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top