The autonumber field ID was giving problem.
When I included it in the insert statement, the same code ran without any problems.
so currently I'm fetching the max(ID) before the insert command to make things work.
It's weird but this thing got working after 2-3 months of wait.
Finally after giving up I posted my problem here.
Does anyone know why this could have occurred?