NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

ColumnsCollection.Add (String)

Creates and adds a DataColumn with the specified name to the columns collection.

[Visual Basic]
Overloads Public Function Add( _
   ByVal columnName As String _
) As DataColumn
[C#]
public DataColumn Add(
   string columnName
);
[C++]
public: DataColumn* Add(
   String* columnName
);
[JScript]
public function Add(
   columnName : String
) : DataColumn;

Parameters

columnName
The ColumnName to create the column with.

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).

Remarks

By default, the column's DataType is string.

If a null reference (in Visual Basic Nothing) or an empty string ("") is passed in for the name, a default name ("Column1", "Column2", etc.) is given to the column.

The Contains method determine whether a column with the proposed name already exists in the collection.

Example [Visual Basic]

The following example creates and adds a new DataColumn to a ColumnsCollection of a DataTable.

[Visual Basic]

Private Sub AddColumn()
   Dim cols As ColumnsCollection
   Dim myCol As DataColumn
   ' Get the ColumnsCollection from a table in a DataSet.
   cols = New DataSet1.Tables("Prices").Columns
   myCol = cols.Add("Total")
   With myCol
      .DataType = System.Type.GetType("System.Currency")
      .ReadOnly = True
      .Expression = "UnitPrice * Quantity"
      .Unique = False
   End With
End Sub

See Also

ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | ColumnsCollection.Add Overload List | ColumnName | Contains | DataType | Expression