Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm getting an error "The SqlParameter is already contained by another SqlParameterCollection" when adding parameters to the sqlcommand. Before adding the parameters I tried by clearing the parameters. But still error comes. My code is like this:
if (parameterArray != null)
  sqlCommand.Parameters.Clear();
sqlCommand.Parameters.AddRange(parameterArray);
Posted
Updated 27-Mar-11 18:50pm
v2

Apperently your parameters are used by another sqlcommand too, this is causing the problem. Clear the parameter collections in all the sqlcommands that are using them.
 
Share this answer
 
Comments
Abhinav S 28-Mar-11 0:53am    
Perfectly accurate answer. 5.
This thread[^] may also give the OP some suggestions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900