我有一个带有复选框列的datagridview,我想要发生的是,当我按下Ok按钮时,它会更新我的EquipmentDetail表中的Requested行以及相应的check chekcbox。
问题在于,当我甚至只检查一个复选框时...即使未在datagridview中检查,所有行都会更新为true ...
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
请帮助我......谢谢......
答案 0 :(得分:1)
在更新语句中,您正在更新EquipmentDetail表中的所有记录,您应该在UPDATE语句中有一个“WHERE”子句。
Dim sql2 As String =“UPDATE EquipmentDetail SET Requested ='”&要求和“'”& “WHERE ID =”& ID( EquipmentDetail表中行的ID )
希望这有帮助!