DataColumn.DefaultValue Property

Gets or sets the default value for the column when you are creating new rows.

Namespace: System.Data
Assembly: System.Data (in

<TypeConverterAttribute(GetType(DefaultValueTypeConverter))> _
Public Property DefaultValue As Object
Dim instance As DataColumn
Dim value As Object

value = instance.DefaultValue

instance.DefaultValue = value
/** @property */
public Object get_DefaultValue ()

/** @property */
public void set_DefaultValue (Object value)

public function get DefaultValue () : Object

public function set DefaultValue (value : Object)

Not applicable.

Property Value

A value appropriate to the column's DataType.

Exception typeCondition


When you are adding a row, the default value is not an instance of the column's data type.

A default value is the value that is automatically assigned to the column when a DataRow is created (for example, the date and time when the DataRow was created.

When AutoIncrement is set to true, there can be no default value.

You can create a new row using the ItemArray property of the DataRow class and passing the method an array of values. This is a potential problem for a column with a default value because its value is generated automatically. To use the ItemArray property with such a column, place a null reference (Nothing in Visual Basic) in the column's position in the array. For more information, see the ItemArray property.

The following example creates several DataColumn objects that have different data types, and sets appropriate default values to each column.

Private Sub CreateColumns()
    Dim column As DataColumn
    Dim table As New DataTable
    column = New DataColumn
    With column
       .DataType = System.Type.GetType("System.String")
       .DefaultValue = "Address"
       .Unique = False
    End With
    column = New DataColumn
    With column
       .DataType = System.Type.GetType("System.Int32")
       .DefaultValue = 100
    End With
    column = New DataColumn
    With column
       .DataType = System.Type.GetType("System.DateTime")
       .DefaultValue = "1/1/2001"
    End With
    Dim row As DataRow
    ' Add one row. Since it has default values, 
    ' no need to set values yet.
    row = table.NewRow
 End Sub

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions