I have a datagrid with checkboxes that lets the user to multiple delete. How do I store the deleted records into a text file? I am using Access to store my data

My code for delete is

 Try
            con.Open()

            For Each row As DataGridViewRow In DataGridView1.Rows
                If row.Cells(0).FormattedValue = True Then

                    Sql = "DELETE FROM member WHERE id = '" _
                    & CStr(row.Cells(1).FormattedValue) & "'"

                    With cmd
                        .Connection = con
                        .CommandText = Sql
                    End With
                    'Execute the Data
                    result = cmd.ExecuteNonQuery
                End If
            Next
            If result = 0 Then
                MsgBox("No Deleted Record.")
            Else
                MsgBox("The Record(s) has been deleted.")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        con.Close()

You need to iterate over all cells BEFORE deletion. ie. foreach(Cell cell in row.Cells){...}
If row.Cells(0).FormattedValue = True Then
WriteCellValuesToFile(row); // new method
Sql = "DELETE FROM member WHERE id = '"

BTW: If result = 0 is AFTER the loop therefore is testing the LAST deletion.

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.