DataColumnCollection.Remove Método
Definição
Remove um objeto DataColumn da coleção.Removes a DataColumn object from the collection.
Sobrecargas
| Remove(DataColumn) |
Remove o objeto DataColumn especificado da coleção.Removes the specified DataColumn object from the collection. |
| Remove(String) |
Remove da coleção o objeto DataColumn que tem o nome especificado.Removes the DataColumn object that has the specified name from the collection. |
Remove(DataColumn)
Remove o objeto DataColumn especificado da coleção.Removes the specified DataColumn object from the collection.
public:
void Remove(System::Data::DataColumn ^ column);
public void Remove (System.Data.DataColumn column);
member this.Remove : System.Data.DataColumn -> unit
Public Sub Remove (column As DataColumn)
Parâmetros
- column
- DataColumn
O DataColumn a ser removido.The DataColumn to remove.
Exceções
O parâmetro column é null.The column parameter is null.
A coluna não pertence a esta coleção.The column does not belong to this collection.
-Ou--Or-
A coluna é parte de uma relação.The column is part of a relationship.
-Ou--Or-
Expressão de outra coluna depende desta coluna.Another column's expression depends on this column.
Exemplos
O exemplo a seguir usa o Contains método para determinar se existe uma coluna nomeada.The following example uses the Contains method to determine whether a named column exists. Nesse caso, a Item[] propriedade retorna a coluna.If so, the Item[] property returns the column. CanRemoveEm seguida, o método verifica se a coluna pode ser removida; nesse caso, o Remove método a remove.The CanRemove method then checks whether the column can be removed; if so, the Remove method removes it.
private void TestAndRemove(DataColumn colToRemove)
{
DataColumnCollection columns;
// Get the DataColumnCollection from a DataTable in a DataSet.
columns = DataSet1.Tables["Orders"].Columns;
if(columns.Contains(colToRemove.ColumnName))
{
columns.Remove(colToRemove);
}
}
Private Sub TestAndRemove(ByVal colToRemove As DataColumn)
' Get the DataColumnCollection from a DataTable in a DataSet.
Dim columns As DataColumnCollection = _
DataSet1.Tables("Orders").Columns
If columns.Contains(colToRemove.ColumnName) Then
columns.Remove(colToRemove)
End If
End Sub
Comentários
Se a coleção for alterada com êxito adicionando ou removendo colunas, o evento de CollectionChanged ocorrerá.If the collection is successfully changed by adding or removing columns, the CollectionChanged event occurs.
Confira também
Aplica-se a
Remove(String)
Remove da coleção o objeto DataColumn que tem o nome especificado.Removes the DataColumn object that has the specified name from the collection.
public:
void Remove(System::String ^ name);
public void Remove (string name);
member this.Remove : string -> unit
Public Sub Remove (name As String)
Parâmetros
- name
- String
O nome da coluna a ser removida.The name of the column to remove.
Exceções
A coleção não tem uma coluna com o nome especificado.The collection does not have a column with the specified name.
Exemplos
O exemplo a seguir primeiro usa o Contains método para determinar se uma determinada coluna foi encontrada na coleção.The following example first uses the Contains method to determine whether a particular column is found in the collection. Se for encontrado, o CanRemove método testará se a coluna pode ser removida.If it is found, the CanRemove method tests whether the column can be removed. Nesse caso, a coluna é removida com o Remove método.If so, the column is removed with the Remove method.
private void RemoveColumnByName(string columnName)
{
// Get the DataColumnCollection from a DataTable in a DataSet.
DataColumnCollection columns =
ds.Tables["Suppliers"].Columns;
if(columns.Contains(columnName))
if(columns.CanRemove(columns[columnName]))
columns.Remove(columnName);
}
Private Sub RemoveColumnByName(columnName As String)
' Get the DataColumnCollection from a DataTable in a DataSet.
Dim columns As DataColumnCollection = _
DataSet1.Tables("Orders").Columns
If columns.Contains(columnName) Then
If columns.CanRemove(columns(columnName)) Then
columns.Remove(columnName)
End If
End If
End Sub
Comentários
Se a coleção for alterada com êxito adicionando ou removendo colunas, o evento de CollectionChanged ocorrerá.If the collection is successfully changed by adding or removing columns, the CollectionChanged event occurs.