Draft for Information Only
    Content 
    
    System.Data Namespace Component DataColumnCollection Class   Definition   In this article  Examples  Remarks  Properties   Methods   Events   Extension Methods  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.
    DataColumnCollection Class  
    Definition 
    
        
            Namespace: 
            System.Data   
        
            Assemblies: 
            System.Data.dll, netstandard.dll, System.Data.Common.dll 
         
    
    
        
            
                Represents a collection of DataColumn  objects for a DataTable .
        
    
    
        In this article 
        
            Definition Examples Remarks Properties Methods Events Extension Methods Applies to Thread Safety See also  
    
    
        C#
    
    
[System.Serializable]
public sealed class DataColumnCollection : System.Data.InternalDataCollectionBase 
    
        Inheritance 
        
            
                
                    Object 
                
                    InternalDataCollectionBase 
                DataColumnCollection
            
         
     
    
        Attributes 
        
            
                SerializableAttribute 
            
         
     
    Examples 
    
        The following example iterates through a collection of DataColumn  objects and prints various properties of each column in the collection.
    
    
        C#
    
    
private void PrintDataTableColumnInfo(DataTable table)
{
    // Use a DataTable object's DataColumnCollection.
    DataColumnCollection columns = table.Columns;
    // Print the ColumnName and DataType for each column.
    foreach(DataColumn column in columns)
    {
        Console.WriteLine(column.ColumnName);
        Console.WriteLine(column.DataType);
    }
}
 
    Remarks 
    
        The DataColumnCollection  defines the schema of a DataTable , and determines what kind of data each DataColumn  can contain. You can access the DataColumnCollection  through the Columns  property of the
        DataTable  object.
    
    
        The DataColumnCollection  uses the Add  and Remove  methods to insert and delete DataColumn  objects. Use the Count  property to determine how many
        DataColumn  objects are in the collection. Use the Contains  method to verify whether a specified index or column name exists in the collection.
    Properties  
    
        
    
    Methods  
    
        
    
    Events  
    
        
            
                CollectionChanged  
                    
                        Occurs when the columns collection changes, either by adding or removing a column.
                 
             
        
    
    Extension Methods 
    
        
    
    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 DataColumnCollection 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 xcols As System.Data.DataColumnCollection
               xstr = xstr + "Declare a table column collection, xcols<br />"
               xcols = xdata.tables(0).Columns
               xstr = xstr + "Assign xdata.tables(0).Columns to table columncollection, xcols <br />"
               xstr = xstr  + "->xcols.Count: " + xcols.Count.ToString + "<br />"
               xstr = xstr  + "->xcols.Item(0).ColumnName: " + xcols.Item(0).ColumnName + "<br />"
               xstr = xstr  + "->xcols.Item(id).DataType: " + xcols.Item("id").DataType.ToString + "<br />"
               xstr = xstr  + "xcols.IndexOf(id): " + xcols.IndexOf("id").ToString + "<br />"
               xstr = xstr  + "xcols.Add(extra1): " + xcols.Add("extra1").ToString + "<br />"
               xstr = xstr  + "xcols.Add(extra2): " + xcols.Add("extra2").ToString + "<br />"
               xstr = xstr  + "xcols.IndexOf(extra1): " + xcols.IndexOf("extra1").ToString + "<br />"
               xstr = xstr  + "->xcols.Count: " + xcols.Count.ToString + "<br />"
               xcols.RemoveAt(4)
               xstr = xstr  + "column extra2 is removed by xcols.RemoveAt(4)<br />"
               xcols.Remove("extra1")
               xstr = xstr  + "column extra1 is removed by xcols.Remove(extra1)<br />"
               xstr = xstr  + "->xcols.Count: " + xcols.Count.ToString + "<br />"
               xcols.Clear()
               xstr = xstr  + "columncollection xcols is cleared by xcols.Clear()<br />"
               xstr = xstr  + "->xcols.Count: " + xcols.Count.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 />"
               xdata.Dispose()
               xstr = xstr + "Dataset xdata is disposed successfully.<br />"
               
               lbl01.Text = xstr
           End Sub
       </script>
    </head>
    <body>
       <% Response.Write ("<h1>This is a Sample Page of DataColumnCollection 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: 201100008 Last Updated: 11/8/2020 Revision: 0 Ref: 
    
References
 Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx  
 ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx  
 ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx  
 ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx  
 Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx  
 Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx  
 Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx  
 Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx  
 Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx  
 ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx  
 ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx  
 Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx  
 How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx  
 Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx  
 IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx  
 ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx  
 Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx  
 Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx  
 ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx  
 FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx  
 http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model  
 ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx