Ok
I checked now and it's working fine.
I am unsure how the same code didn't work previously.
Though I recall I did a change on my table prev where my primary key was set to int but I was inserting string primary keys. So I changed it to varchar. May be for this reason my records were not inserting. Btw, after the above code I do a check if any matches returned and do an insert accordingly.