[英]flagging vb.net with sql
請幫助使用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
感謝您的考慮,請提前幫助
如果您的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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.