Is it not easier the create an array with the x elements and values you need.
Then explode this array in the SQL syntax for the values? This way you create one SQL insert statement that will insert x values at once. This will avoid sql server load. Imagine you need to insert 10000 recors withing a loop will cause a much havier load on the server while having one insert statement with 10000 values will be much faster.
Just my idea.