Sideway
output.to from Sideway
Draft for Information Only

Content

System.Data Namespace Component
DataColumn Class
 Definition
  In this article
 Examples
 Remarks
 Constructors
 Properties
 Methods
 Events
 Applies to
   .NET Core
   .NET Framework
   .NET Standard
   Xamarin.Android
   Xamarin.iOS
   Xamarin.Mac
 Thread Safety
 See also
 Examples
 Source/Reference

System.Data Namespace Component

The System.Data namespace provides access to classes that represent the ADO.NET architecture. ADO.NET lets you build components that efficiently manage data from multiple data sources.

DataColumn Class

Definition

Namespace:
System.Data
Assemblies:
System.Data.dll, netstandard.dll, System.Data.Common.dll

Represents the schema of a column in a DataTable.

In this article

  1. Definition
  2. Examples
  3. Remarks
  4. Constructors
  5. Properties
  6. Methods
  7. Events
  8. Applies to
  9. Thread Safety
  10. See also
C#
public class DataColumn : System.ComponentModel.MarshalByValueComponent
Inheritance
Object MarshalByValueComponent DataColumn

Examples

The following example creates a DataTable with several DataColumn objects.

C#
private void MakeTable()
{ 
    // Create a DataTable. 
    DataTable table = new DataTable("Product");

    // Create a DataColumn and set various properties. 
    DataColumn column = new DataColumn(); 
    column.DataType = System.Type.GetType("System.Decimal"); 
    column.AllowDBNull = false; 
    column.Caption = "Price"; 
    column.ColumnName = "Price"; 
    column.DefaultValue = 25; 

    // Add the column to the table. 
    table.Columns.Add(column); 

    // Add 10 rows and set values. 
    DataRow row; 
    for(int i = 0; i < 10; i++)
    { 
        row = table.NewRow(); 
        row["Price"] = i + 1; 

        // Be sure to add the new row to the 
        // DataRowCollection. 
        table.Rows.Add(row); 
    } 
}

Remarks

The DataColumn is the fundamental building block for creating the schema of a DataTable. You build the schema by adding one or more DataColumn objects to the DataColumnCollection. For more information, see Adding Columns to a DataTable.

Each DataColumn has a DataType property that determines the kind of data the DataColumn contains. For example, you can restrict the data type to integers, or strings, or decimals. Because data that is contained by the DataTable is typically merged back into its original data source, you must match the data types to those in the data source. For more information, see Data Type Mappings in ADO.NET.

Properties such as AllowDBNull, Unique, and ReadOnly put restrictions on the entry and updating of data, thereby helping to guarantee data integrity. You can also use the AutoIncrement, AutoIncrementSeed, and AutoIncrementStep properties to control automatic data generation. For more information about AutoIncrement columns, see Creating AutoIncrement Columns. For more information, see Defining Primary Keys.

You can also make sure that values in a DataColumn are unique by creating a UniqueConstraint and adding it to the ConstraintCollection of the DataTable to which the DataColumn belongs. For more information, see DataTable Constraints.

To create a relation between DataColumn objects, create a DataRelation object and add it to the DataRelationCollection of a DataSet.

You can use the Expression property of the DataColumn object to calculate the values in a column, or create an aggregate column. For more information, see Creating Expression Columns.

Constructors

DataColumn()

Initializes a new instance of a DataColumn class as type string.

DataColumn(String)

Initializes a new instance of the DataColumn class, as type string, using the specified column name.

DataColumn(String, Type)

Initializes a new instance of the DataColumn class using the specified column name and data type.

DataColumn(String, Type, String)

Initializes a new instance of the DataColumn class using the specified name, data type, and expression.

DataColumn(String, Type, String, MappingType)

Initializes a new instance of the DataColumn class using the specified name, data type, expression, and value that determines whether the column is an attribute.

Properties

AllowDBNull

Gets or sets a value that indicates whether null values are allowed in this column for rows that belong to the table.

AutoIncrement

Gets or sets a value that indicates whether the column automatically increments the value of the column for new rows added to the table.

AutoIncrementSeed

Gets or sets the starting value for a column that has its AutoIncrement property set to true. The default is 0.

AutoIncrementStep

Gets or sets the increment used by a column with its AutoIncrement property set to true.

Caption

Gets or sets the caption for the column.

ColumnMapping

Gets or sets the MappingType of the column.

ColumnName

Gets or sets the name of the column in the DataColumnCollection.

Container

Gets the container for the component.

(Inherited from MarshalByValueComponent)
DataType

Gets or sets the type of data stored in the column.

DateTimeMode

Gets or sets the DateTimeMode for the column.

DefaultValue

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

DesignMode

Gets a value indicating whether the component is currently in design mode.

(Inherited from MarshalByValueComponent)
Events

Gets the list of event handlers that are attached to this component.

(Inherited from MarshalByValueComponent)
Expression

Gets or sets the expression used to filter rows, calculate the values in a column, or create an aggregate column.

ExtendedProperties

Gets the collection of custom user information associated with a DataColumn.

MaxLength

Gets or sets the maximum length of a text column.

Namespace

Gets or sets the namespace of the DataColumn.

Ordinal

Gets the (zero-based) position of the column in the DataColumnCollection collection.

Prefix

Gets or sets an XML prefix that aliases the namespace of the DataTable.

ReadOnly

Gets or sets a value that indicates whether the column allows for changes as soon as a row has been added to the table.

Site

Gets or sets the site of the component.

(Inherited from MarshalByValueComponent)
Table

Gets the DataTable to which the column belongs to.

Unique

Gets or sets a value that indicates whether the values in each row of the column must be unique.

Methods

CheckNotAllowNull()

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

CheckUnique()

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Dispose()

Releases all resources used by the MarshalByValueComponent.

(Inherited from MarshalByValueComponent)
Dispose(Boolean)

Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources.

(Inherited from MarshalByValueComponent)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetService(Type)

Gets the implementer of the IServiceProvider.

(Inherited from MarshalByValueComponent)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnPropertyChanging(PropertyChangedEventArgs)

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

RaisePropertyChanging(String)

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

SetOrdinal(Int32)

Changes the ordinal or position of the DataColumn to the specified ordinal or position.

ToString()

Gets the Expression of the column, if one exists.

Events

Disposed

Adds an event handler to listen to the Disposed event on the component.

(Inherited from MarshalByValueComponent)

Applies to

.NET Core

3.0 Preview 8 2.2 2.1 2.0

.NET Framework

4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

.NET Standard

2.1 Preview 2.0

Xamarin.Android

7.1

Xamarin.iOS

10.8

Xamarin.Mac

3.0

Thread Safety

This type is safe for multithreaded read operations. You must synchronize any write operations.

See also

 

Examples

Examples of DataColumn Class
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
       <title>Sample Page</title>
       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
       <script runat="server" >
           Sub Page_Load()
               Dim xstr As String
               Dim xconn As New System.Data.OleDb.OleDbConnection
               xconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=T:\test.mdb;User Id=admin;Password=;"
               xconn.Open()
               xstr = xstr + "Connection xconn to database test.mdb  is opened successfully.<br />"
               Dim xdata As New System.Data.DataSet
               Dim xadapt As System.Data.OleDb.OleDbDataAdapter
               Dim sql As String = "SELECT * FROM T1"
               xadapt = New System.Data.OleDb.OleDbDataAdapter(sql, xconn)
               xstr = xstr + "Dataadapter xadapt is assigned to SELECT * FROM T1 through xconn successfully.<br />"
               xadapt.Fill(xdata,"T1")
               xstr = xstr + "Dataset xdata is filled by xadapt.fill successfully.<br />"
               xstr = xstr + "<br />"
               Dim xcol As System.Data.DataColumn
               xstr = xstr + "Declare a table column, xcol<br />"
               xcol = xdata.tables(0).Columns(0)
               xstr = xstr + "Assign xdata.tables(0).Columns(0) to table column, xcol <br />"
               xstr = xstr  + "->xcol.ColumnName: " + xcol.ColumnName + "<br />"
               xstr = xstr  + "->xcol.Caption: " + xcol.Caption + "<br />"
               xstr = xstr  + "->xcol.Ordinal: " + xcol.Ordinal.ToString + "<br />"
               xstr = xstr  + "->xcol.DataType: " + xcol.DataType.ToString + "<br />"
               xstr = xstr  + "->xcol.MaxLength: " + xcol.MaxLength.ToString + "<br />"
               xstr = xstr  + "->xcol.DefaultValue: " + xcol.DefaultValue + "<br />"
               xstr = xstr  + "->xcol.AllowDBNull: " + xcol.AllowDBNull.ToString + "<br />"
               
               xstr = xstr + "<br />"
               xadapt.Dispose()
               xstr = xstr + "Dataadapter xadapt is disposed successfully.<br />"
               xconn.Close()
               xstr = xstr + "Connection xconn is closed successfully.<br />"
               xstr = xstr + "Dataset xdata.tables(T1).rows(0).item(1):" + xdata.Tables("T1").Rows(0).Item("f1") + "<br />"
               xdata.Dispose()
               xstr = xstr + "Dataset xdata is disposed successfully.<br />"
               
               lbl01.Text = xstr
           End Sub
       </script>
    </head>
    <body>
<%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
       <% Response.Write ("<h1>This is a Sample Page of DataColumn Class</h1>") %>
       <p>
           <%-- Set on Page_Load --%>
           <asp:Label id="lbl01" runat="server" />
       </p>
    </body>
</html>
HTML Web Page Embedded Output:

Source/Reference


©sideway

ID: 201100007 Last Updated: 11/7/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019