I am not able to figure out whats wrong with this code. i am clearing all the parameters and then adding them but it still gives me the error saying "The SqlParameter is already contained by another SqlParameterCollection."
Please help
using (SqlConnection m_Connection = Class_SetApplicationEnviroment.Get_Sql_Connection())
{
m_Connection.Open();
SqlCommand oSqlCommand = new SqlCommand(m_spName, m_Connection);
oSqlCommand.CommandType = CommandType.StoredProcedure;
if (m_Parameters.Length > 0)
{
//SQLDataAdapter.SelectCommand.Parameters.Clear();
oSqlCommand.Parameters.Clear();
foreach (SqlParameter oParam in m_Parameters)
{
if (oParam != null)
{
// Check for derived output value with no value assigned
if ((oParam.Direction == ParameterDirection.InputOutput ||
oParam.Direction == ParameterDirection.Input) &&
(oParam.Value == null))
{
oParam.Value = null;
}
oSqlCommand.Parameters.Add(oParam);
//SQLDataAdapter.SelectCommand.Parameters.Add(oParam);
}
}
}
//Execute the Stored Procedure
//SQLDataAdapter.Fill(myTable);
strReturnValue = oSqlCommand.ExecuteNonQuery().ToString();
m_Connection.Close();
}
}