System.Data Namespace DataColumnCollection Class
Initializes and adds a DataColumn with the specified name, type, and expression to the columns collection.
[ VB ]
Overloads Public Function Add ( _
ByVal columnName As String, _
ByVal type As Type, _
ByVal expression As String _
) As DataColumn
[ C# ]
public virtual DataColumn Add (
string columnName,
Type type,
string expression
);
[ C++ ]
public: virtual DataColumn* Add (
String* columnName,
Type* type,
String* expression
);
[ JScript ]
public function Add (
columnName : String,
type : Type,
expression : String
) : DataColumn;
- columnName
- The name to give to the column.
- type
- The DataType of the column.
- expression
- The expression to assign to the Expression property.
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 ( )
' get the DataColumnCollection of a table in a DataSet.
Dim cols As DataColumnCollection = ds.Tables ( "Orders" ).Columns
' add a new column
Dim myCol As DataColumn = cols.Add ( "Total", System.Type.GetType ( "System.Decimal" ), _
"Price + Tax" )
myCol.ReadOnly = True
myCol.Unique = False
End Sub
DataColumnCollection Members DataColumnCollection.Add Overload List ColumnName DataType Expression