Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataColumn.AllowDBNull Property

Gets or sets a value indicating whether null values are allowed in this column for rows belonging to the table.

[Visual Basic]
Public Property AllowDBNull As Boolean
[C#]
public bool AllowDBNull {get; set;}
[C++]
public: __property bool get_AllowDBNull();
public: __property void set_AllowDBNull(bool);
[JScript]
public function get AllowDBNull() : Boolean;
public function set AllowDBNull(Boolean);

Property Value

true if null values values are allowed; otherwise, false. The default is true.

Example

[Visual Basic, C#, C++] The following example creates a new DataColumn and sets its AllowDBNull property to true.

[Visual Basic] 
Private Sub AddNullAllowedColumn()
 Dim myColumn As DataColumn
 myColumn = New DataColumn("classID", System.Type.GetType("System.Int32"))
 myColumn.AllowDBNull = True
 ' Add the column to a new DataTable.
 Dim myTable As DataTable
 myTable = New DataTable
 myTable.Columns.Add(myColumn)
 End Sub

[C#] 
private void AddNullAllowedColumn(){
    DataColumn myColumn;
    myColumn = new DataColumn("classID", System.Type.GetType("System.Int32"));
    myColumn.AllowDBNull = true;
    // Add the column to a new DataTable.
    DataTable myTable;
    myTable = new DataTable();
    myTable.Columns.Add(myColumn);
 }

[C++] 
private:
void AddNullAllowedColumn(){
    DataColumn* myColumn;
    myColumn = new DataColumn(S"classID", System::Type::GetType(S"System.Int32"));
    myColumn->AllowDBNull = true;
    // Add the column to a new DataTable.
    DataTable* myTable;
    myTable = new DataTable();
    myTable->Columns->Add(myColumn);
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumn Class | DataColumn Members | System.Data Namespace | Unique

Show:
© 2017 Microsoft