SqlParameter Collections

  • Thread starter Thread starter Jimmy V
  • Start date Start date
J

Jimmy V

The SqlParameter is already contained by another
SqlParameterCollection.

Ok, this one is just one of those bitch-fest / show me the way posts.
Why does .NET throw this error? It seems to me that it goes against
the concept of reusablity making you have to destroy and recreate the
collection (or individual parameter if it is needed for another call)
each time you need to use it. For instance, I have to populate a
series of dropdowns based on a user's id. For me to make my procedure
calls, I have to create a separate parameter each time. Perhaps I am
just missing the point and I am sure there is a reason (good, bad, or
Microsoft) for doing it this way, and was just hoping for my own
edification, and possibly the edifiacation of others, for some
information on this.

Thanks and happy coding!
 
The SqlParameter is already contained by another
SqlParameterCollection.

Ok, this one is just one of those bitch-fest / show me the way posts.
Why does .NET throw this error? It seems to me that it goes against
the concept of reusablity making you have to destroy and recreate the
collection (or individual parameter if it is needed for another call)
each time you need to use it. For instance, I have to populate a
series of dropdowns based on a user's id. For me to make my procedure
calls, I have to create a separate parameter each time. Perhaps I am
just missing the point and I am sure there is a reason (good, bad, or
Microsoft) for doing it this way, and was just hoping for my own
edification, and possibly the edifiacation of others, for some
information on this.

Thanks and happy coding!

LOL.. Actually, that's always been sort of a pet peve of mine as well. I'm
not exactly sure why it was implemented that way. It made my life a real pain
implementing a parameter cache.
 
The SqlParameter is already contained by another
SqlParameterCollection.

Ok, this one is just one of those bitch-fest / show me the way posts.
Why does .NET throw this error? It seems to me that it goes against
the concept of reusablity making you have to destroy and recreate the
collection (or individual parameter if it is needed for another call)
each time you need to use it.

I takes a little bit of extra coding and a little bit of extra
GC, but you avoid the risk of some very nasty problems with
multithreaded code and out parameters.

Arne
 
Back
Top