I'm hoping someone can help me out with this. I have a datatable populated from an SQL Server 2008 database table. I created a DataAdapter with a commandbuilder to manage the updating, inserting, and deleting of records. The Updating and Inserting work as expected. However, Delete does not. The code runs through just fine without any errors. The number of records in the datatable after the row is deleted even reflects the deletion. The DataAdapter.Update works fine without any exceptions. But when checking the actual table in the SQL DB the deleted record is still there.
Here are the parts of my code that deal with this table.

Public Class cADC
    Public dsADC As DataSet
    Private adptADC As SqlDataAdapter
    Private adptChanges As SqlDataAdapter
    Private v_ADCID As Long

    Public Sub New(Optional ByVal ADC_ID As Long = 0)
        dsADC = New DataSet
        v_ADCID = ADC_ID
        RefreshADC()
        RefreshChanges()
    End Sub

    Public Sub RemoveChange(ByVal OrderNum As Integer)
        Try
            'removes a row from the change table for the unique OrderNum provided by the user.
            Dim ChangeCount As Integer = 0
            Dim i As Integer = 0
            Dim Removed As Boolean = False
            ChangeCount = dsADC.Tables("Changes").Rows.Count
            Dim dt As DataTable = dsADC.Tables("Changes")
            If OrderNum < 0 Or OrderNum > ChangeCount Then Exit Sub
            While Not Removed And i < ChangeCount
                If dsADC.Tables("Changes").Rows(i).Item("ORDER_NUM") = OrderNum Then
                    dsADC.Tables("Changes").Rows.RemoveAt(i)
                    Removed = True
                End If
                i += 1
            End While
            'ReOrder Nums
            If OrderNum < ChangeCount Then
                For i = OrderNum + 1 To ChangeCount
                    ReOrderChanges(i, i - 1)
                Next
            End If
        Catch ex As Exception
            ErrorHandler("cADC.RemoveChange", ex.ToString)
        End Try
    End Sub

    Public Sub AddChange(ByVal ChangeRow As DataRow)
        Try
            Cursor.Current = Cursors.WaitCursor
            dsADC.Tables("Changes").Rows.Add(ChangeRow)
            RefreshChangeDisplay()
        Catch ex As Exception
            ErrorHandler("cADC.AddChange", ex.ToString)
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub

    Public Function Save() As Boolean
        Try
            Cursor.Current = Cursors.WaitCursor
            adptADC.Update(dsADC.Tables("ADCRequest"))
            If v_ADCID = 0 Then
                v_ADCID = GetNewID()
                'if this is a new ADC, then add the ADCID to each row in the Changes
                With dsADC.Tables("Changes")
                    For i As Integer = 0 To .Rows.Count - 1
                        .Rows(i).Item("ADCID") = v_ADCID
                    Next
                End With
            End If
            If v_ADCID > 0 Then
                'if this is an existing ADC apply all modifications to the Changes table
                adptChanges.Update(dsADC, "Changes")
            End If
            Return (v_ADCID > 0)
        Catch ex As Exception
            ErrorHandler("cADC.Save", ex.ToString)
            Return False
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Function

Any help you can provide would be most appreciated.
Thanks!

resolved. Used .Delete instead of .RemoveAt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.