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