Because this line of code you wrote:
"Line No.":="Line No."+10000;
is wrong.
Here, at the first record Line No is 0 (data imported from external) and then you assign 0 + 10000 = 10000, the line is inserted.
At the second record imported, Line No is always 0 (data imported from external), you assign 0 + 10000 = 10000, this Line No. now exists and you receive an error.
A function is used to retrieve the last Line No. inserted in the table.
P.S. I've suggested a function because it's more elegant and it's the best way to do for "code readability", but you can also write the code I've suggest you directly in OnAfterGetRecord without using a function.