8
Answers

The SqlParameter is already contained by another SqlParamet

Krishna Kumar

Krishna Kumar

8y
748
1
Hello...
 
i am passing the stored procedure name and parameter collection to this method. but while executing it is giving the error, The SqlParameter is already contained by another SqlParameter. eventhough i have added the parameters.clear() function to clear the parameters. but it is giving the same error
 
public void executeSP(string spname, SqlParameterCollection sp)
{
int retobj = 0;
//open connection
con.Open();
//execute SP
cmd = new SqlCommand(spname, con);
cmd.CommandType = CommandType.StoredProcedure;
if (sp.Count > 0)
{
foreach (SqlParameter p in sp)
{
cmd.Parameters.Add(p);
cmd.Parameters.Clear();
}
}
retobj=cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
//Close connection
con.Close();
Answers (8)