0
votes

I have a datagridview with a checkbox column at the beginning, what i want to happen is that when I press the Ok button it will update the Requested row in my EquipmentDetail table with the corresponding checked chekcboxes.

The problem is that when I check even only one checkbox ... All of the rows are updated into true even if its not checked in the datagridview ...

 For Each row As DataGridViewRow In DataGridView1.Rows
        req = row.Cells(Column1.Name).Value
        If row.Cells("Column1").Value = True Then
            Dim sql2 As String = "UPDATE EquipmentDetail SET Requested = '" & req & "'"
            cmd2.Connection = connection
            cmd2.CommandText = sql2
            cmd2.ExecuteNonQuery()
        End If
    Next
    connection.Close()
End Sub

help me please ... thanks ...

1

1 Answers

1
votes

In your update statement you are updating all records in the EquipmentDetail table, you should have a "WHERE" clause in the UPDATE statement.

Dim sql2 As String = "UPDATE EquipmentDetail SET Requested = '" & req & "'" & "WHERE ID=" & ID(the id of the Row in the EquipmentDetail table)

Hope this helps!