public void CollectionRemove() { SqlCommand command = new SqlCommand(); SqlParameterCollection collection = command.Parameters; SqlParameter parameter1 = new SqlParameter("Test1", 1); collection.Add(parameter1); collection.Add(new SqlParameter("Test2", 2)); collection.Add(new SqlParameter("Test3", 3)); collection.Remove(parameter1); Assert.Equal(2, collection.Count); Assert.Equal("Test2", collection[0].ParameterName); }
/// <summary> /// Remove the SqlParameter with the specified name. /// </summary> /// <param name="name">The name of the SqlParameter to remove.</param> /// <returns>Whether or not the command was successfully removed.</returns> public bool RemoveParameter(string name) { SqlParameter rm = null; foreach (SqlParameter param in Parameters) { if (param.ParameterName == name) { rm = param; } } if (rm != null) { Parameters.Remove(rm); return(true); } return(false); }