asp.net.ph

DataColumnCollection.Add Method ( String, Type, String )

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;

Parameters

columnName
The name to give to the column.
type
The DataType of the column.
expression
The expression to assign to the Expression property.

Return Value

The newly created DataColumn.

Exceptions


Exception Type Condition
DuplicateNameException The collection already has a column with the same name ( the comparison is not case-sensitive ).
InvalidExpressionException The expression is invalid. See the Expression property for details on creating expressions.

Remarks

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.

Example

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
See Also

DataColumnCollection Members   DataColumnCollection.Add Overload List   ColumnName   DataType   Expression Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph