If i am reading your code correctly you are reading from one table and adding to another and never use the data in your application. If this is a case then best case scenario is to write a db procedure that will transform your data and execute it from your app.