i have written the code for the update but its not working. when i run the break point debugger it goes to infinite loop.
my update button click code
Public Sub Updates()
If con.State = ConnectionState.Open Then
con.Close()
End If
Dim i As Integer
Try
For i = 0 To dgv.Rows.Count - 1
Dim cmd As New SqlClient.SqlCommand("Update tblProductsve set ItemCode=('" & dgv.Rows(i).Cells(1).Value & "'),srno=('" & dgv.Rows(i).Cells(0).Value & "'), ItemDes=('" & dgv.Rows(i).Cells(2).Value & "'), Price=('" & dgv.Rows(i).Cells(3).Value & "'),Qty=('" & dgv.Rows(i).Cells(4).Value & "'),amt=('" & dgv.Rows(i).Cells(5).Value & "'),subtot=('" & txtBSearch.Text & "') where billid=('" & txtBSearch.Text & "'))", con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Next
MessageBox.Show("Updated Successully ")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
below code is going to infinite loop
Private Sub dgv_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles dgv.RowPostPaint
If con.State = ConnectionState.Open Then
con.Close()
End If
Me.dgv.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1.ToString
dgv.Columns(0).ReadOnly = True
End Sub
please help me where should i make correction