من کد برنامم رو به جای اینکه insert کنم و delete کنم به این صورت نوشتم و بهش گفتم که اگر همچین ردیفی وجود داره عمل insert رو انجام بده ولی نمی دونم چرا خطای زیر رو داد
If DataGridView1.CurrentRow.Cells(0).Value Then
For j AsInteger = 0 To DataGridView2.RowCount - 1
If DataGridView2.Rows(j).Cells(0).Value Then
If DataGridView2.Rows(j).Cells(4).Value <> 0 Then
a = DataGridView1.CurrentRow.Cells(4).Value / DataGridView2.Rows(j).Cells(4).Value
m = (DataGridView1.CurrentRow.Cells(1).Value * 100) + DataGridView2.Rows(j).Cells(1).Value
cmd.CommandText = " select * from shakhes2 where idshakhes='" & m & "' and sal81 = '" & a & "'"
dr = cmd.ExecuteReader()
If dr.hasrows = TrueThen
dr.read()
cmd.CommandText = " UPDATE shakhes2 SET idshakhes,sal81 =" & m & "," & a & " WHERE idshakhes = " & m
cmd.ExecuteNonQuery()
Else
cmd.CommandText = " INSERT INTO shakhes2(idshakhes,sal81) VALUES(@m,@a)"
cmd.Parameters.Add("@idshakhes", SqlDbType.Int)
cmd.Parameters.Add("@sal81", SqlDbType.Int)
cmd.Parameters("@idshakhes").Value = m
cmd.Parameters("@sal81").Value = a
cmd.ExecuteNonQuery()
EndIf
Else : a = 0
EndIf
EndIf
Next
پیغام خطایی که صادر می کنه