System.Data Namespace DataColumnCollection Class
Initializes and adds a DataColumn with the specified name and type to the columns collection.
[ VB ]
Overloads Public Function Add ( _
ByVal columnName As String, _
ByVal type As Type _
) As DataColumn
[ C# ]
public virtual DataColumn Add (
string columnName,
Type type
);
[ C++ ]
public: virtual DataColumn* Add (
String* columnName,
Type* type
);
[ JScript ]
public function Add (
columnName : String,
type : Type
) : DataColumn;
- columnName
- The name of the column.
- type
- The column’s DataType.
The newly created DataColumn.
If a null reference or an empty string ( "" ) is passed in for the name, a default name ( "Column1", "Column2", etc. ) is given to the column.
Use the Contains method to determine whether a column with the proposed name already exists in the collection.
If the collection is successfully changed by adding or removing columns, the CollectionChanged event occurs.
The following example initializes and adds a new DataColumn to the DataColumnCollection of a DataTable using this constructor.
Private Sub AddColumn ( )
Dim cols As DataColumnCollection = New ds.Tables ( "Orders" ).Columns
' add a new column
Dim myCol As DataColumn = cols.Add ( "Total", System.Type.GetType ( "System.Decimal" ) )
myCol.ReadOnly = True
myCol.Unique = False
End Sub
DataColumnCollection Members DataColumnCollection.Add Overload List ColumnName DataType