I have written insert and update queries in DGV_rowleave event as
sql = "insert into table1(Sno,BriefDescription,Jan) values(" & DGV(0, e.RowIndex).Value & ",'" & DGV(1, e.RowIndex).Value & "'," & DGV(2, e.RowIndex).Value & " )"
adp.InsertCommand = sqlcon.CreateCommand()
adp.InsertCommand.CommandText = sql
adp.InsertCommand.ExecuteNonQuery()
sql1 = "UPDATE table1 SET Year=" & cbyears.SelectedItem & " where Sno=" & DGV(0, e.RowIndex).Value.ToString() & " "
adp.UpdateCommand = sqlcon.CreateCommand
adp.UpdateCommand.CommandText = sql1
adp.UpdateCommand.ExecuteNonQuery()
queries are executing fine and databse is also updating……
As I hve written this lines in dgv_rowleave event, every time this code is executing and getting error as:Validation of primary key constraint:cannot insert duplicate key..
Even while form(having DGV) loading also this error is coming..
When I perform changes to my DGV after loading the form then only row_leave event wants to be execute,how?
Please give any idea..