DataColumn

A DataColumn represents a single column (or field) in a DataTable (or in a DataRow).
All columns by default can contain Null values (assuming they are not primary keys.



Creating a DataColumn Object

Dim objDataColumn As System.Data.DataColumn 
objDataColumn = New System.Data.DataColumn
objDataColumn.ColumnName = "NameOfColumn"
objDataColumn.DataType = System.Type.GetType("System.String")

Alternatively you can pass the column name and the data type directly to the constructor

Dim objDataColumn As New System.Data.DataColumn("NameOfColumn", GetType(String)) 

Column DataTypes

objDataColumn.DataType = System.Type.GetType("System.String") 
objDataColumn.DataType = System.Type.GetType("System.Int32")
objDataColumn.DataType = System.Type.GetType("System.Boolean")
objDataColumn.DataType = System.Type.GetType("System.DateTime")
objDataColumn.DataType = System.Type.GetType("System.Double")
objDataColumn.DataType = System.Type.GetType("System.Decimal")
objDataColumn.DataType = System.Type.GetType("System.Char")
objDataColumn.DataType = System.Type.GetType("System.TimeSpan")
objDataColumn.DataType = System.Type.GetType("System.Single")
objDataColumn.DataType = System.Type.GetType("System.Int16")

Adding a DataColumn to a DataTable

objDataColumn.MaxLength = 100 
objDataTable.Columns.Add(objDataColumn)

Alternatively you can create an implicit DataColumn with the Columns.Add method

With objDataTable.Columns.Add("NameOfColumn", GetType(String)) 
   .MaxLength = 100
End With
'or even
objDataTable.Columns.Add("NameOfColumn", GetType(String)).MaxLength = 100

Creating an Expression

objDataColumn.Expression = "FirstName + LastName" 




Properties

AllowDBNullA boolean that determines whether null values can be accepted for this column. The default is True.
AutoIncrementA boolean that determines whether this is an auto-incrementing column.
AutoIncrementSpeedThe starting value for an auto-incrementing column.
AutoIncrementStepThe increment value for an auto-incrementing column.
CaptionThe caption to be used for this column in the user interface
ColumnMappingThe MappingType of this column, which is how this column is rendered as XML. It can be Element, Attribute, SimpleContent or Hidden.
ColumnNameThe name of this column.
ContainerAn object implementing the IContainer interface that represents the component's container, or a null reference (Nothing in Visual Basic) if the component does not have a site.
DataTypeThe System.Type object that defines the data type of this column.
DefaultValueThe default value for this column when a new row is added to the table.
DesignMode 
ExpressionThe expression to be used for calculated columns.
ExtendedPropertiesReturns the PropertyCollection object used to store custom information about the DataColumn.
MaxLengthThe maximum length of a text column.
NamespaceThe namespace for this DataTable, used when importing or exporting XML data.
OrdinalThe position of this column in the DataColumnCollection
PrefixThe XML prefix for the DataTable namespace.
ReadOnlyA boolean that determines whether values in this column can be modified after the row has been added to the table.
Site 
TableThe DataTable this column belongs to.
UniqueA boolean that determines whether duplicated values are accepted in this column.

Methods

Dispose 
GetService 
GetType 
ToString 

© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext