用sql标记vb.net

时间:2013-09-01 07:29:03

标签: sql sql-server vb.net vb.net-2010

请帮助标记 使用vb.net和sql server 我希望当datagridview中的所选数据双击时,删除的值(1)将以青色突出显示

这是我的代码

  Private Sub showme()

    Dim i As Integer


        For i = 0 To dgvDoctorsList.RowCount > -1
            Dim remrks = dgvDoctorsList.Rows(i).Cells(6).Value
        If remrks = "1" Then
            dgvDoctorsList.Rows(i).DefaultCellStyle.BackColor = Color.Cyan
        End If

        Next


End Sub

Private Sub dgvDoctorsList_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDoctorsList.CellDoubleClick

    If MessageBox.Show("Are you sure want to delete this data ?", "CONFIRMATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then

        Dim objCmd As New SqlCommand()
        Using con As New SqlConnection("server=ACHACOSOFAMILY;database=jjasgh;integrated security=true")
            objCmd.Connection = con
            con.Open()

            For Each objRow As DataGridViewRow In dgvDoctorsList.SelectedRows
                objCmd.CommandText = "Update tbl_Doctor SET Remarks=1 where License_no=@license"

                objCmd.Parameters.AddWithValue("@license", dgvDoctorsList.CurrentRow.Cells(0).Value)
                objCmd.ExecuteNonQuery()
                showme()

            Next
        End Using
     End sub

感谢您的帮助 提前谢谢

1 个答案:

答案 0 :(得分:0)

如果您的doubleclick事件运行良好,那么您必须在RowPrepaint事件中执行此操作。

Private Sub dgvDoctorsList_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles dgvDoctorsList.RowPrePaint
    Dim x as Integer = e.RowIndex

    If dgvDoctorsList.Rows(x).Cells("remarks").Value= 1 Then
        dgvDoctorsList.Rows(x).DefaultCellStyle.BackColor = Color.Cyan
    End If
End Sub