开发者

SqlParamater updating values in a loop - side effects

开发者 https://www.devze.com 2022-12-12 03:04 出处:网络
I have a stored proc that takes one integer parameter. I am calling this in a loop (I would rather use an In but Stored proc is outwith my control).

I have a stored proc that takes one integer parameter.

I am calling this in a loop (I would rather use an In but Stored proc is outwith my control).

So I have one SqlParameter object who's value is updated each time round a loop.

I have a vag开发者_如何学Pythonue memory of there being a side effect to this? Does this ring any bells?

(.NET 2.0 / SQL Server 2005)


If the code is reasonably straightforward and you're just updating the parameter's value on each iteration then I'd consider this good practice.

There aren't any side effects that I'm aware of.


The main side effect that comes to mind is poor performance.

If you can do the loop on the server side instead (best), or at least combine multiple statements into a single batch, you will be much better off.

0

精彩评论

暂无评论...
验证码 换一张
取 消