0

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()

Edited by hfuehf: added

2
Contributors
2
Replies
26
Views
2 Years
Discussion Span
Last Post by SteveDotNet
0

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 = '"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.