2013-09-01 30 views
0

請用vb.net和SQL Server 我想刪除的值(1)將突出顯示青色時的DataGridView選定的數據是雙擊與SQL萎靡不振vb.net

此標記 幫助是我的代碼

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 [email protected]" 

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

      Next 
     End Using 
    End sub 

感謝考慮請幫助 在此先感謝

回答

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