Copy and Clone

the using the System;
 the using the System.Collections.Generic;
 the using the System.Data;
 the using the System.Linq;
 the using the System.Text;
 the using System.Threading.Tasks; 

namespace community learning 
{ 
    class Program 
    { 
        static  void the Main ( String [] args) 
        { 
            ParentDataTable A = new new ParentDataTable (); 
            the DataTable DT1 = a.ParentD () the copy ();.   // copy, data structures and the like including information 
            Console.WriteLine (dt1.Rows [ 0 ] [ " the Name" ] .ToString ()); 
            the DataTable DT2 = a.ParentD () Clone ();.   // copy only the structure and relationships 
            Console.WriteLine (dt2.Rows [ 0 ] [ " the Name " ] .ToString ()); 
            the Console.ReadKey (); 
        } 
    } 
    class ParentDataTable 
    { 
        public the DataTable ParentD () 
        { 
            the DataTable l_dtTable = new new the DataTable ();   // Create a Datatable
             // build frame Datatable 
            the DataColumn l_dtColumn = l_dtTable.Columns.Add ( " ID ", The Type.GetType ( " the System.Int16 " ));   // Set the attribute column 
            l_dtColumn.AllowDBNull = to false ;   // if null values allowed 
            l_dtColumn.AutoIncrement = to true ;   // automatically increase 
            l_dtColumn.AutoIncrementSeed = . 1 ;   // Set starting value 
            l_dtColumn.AutoIncrementStep = . 1 ;   // Sets the step 
            l_dtColumn.Unique = to true ;   // set uniquely 
            the DataColumn l_dtColumn2 = l_dtTable.Columns.Add ( " the Name ", The Type.GetType ( " System.String The " )); 
            l_dtColumn2.DefaultValue = "" ;   // Set Default 
            l_dtColumn2.MaxLength = 20 is ;   // set the maximum length 
            l_dtTable.Columns.Add ( " Sex " , the Type.GetType ( " System.Boolean The " ));   // set the attribute field 
            the DataRow l_drOne l_dtTable.NewRow = ();   // create a new line 
            l_drOne [ " the Name " ] = " namejr " ; 
            l_drOne ["Sex"] = true;
            l_dtTable.Rows.Add(l_drOne);  // 添加一行
            DataRow l_drTwo = l_dtTable.NewRow();
            l_drTwo["Name"] = "namejr";
            l_drTwo["Sex"] = true;
            l_dtTable.Rows.Add(l_drTwo);
            return l_dtTable;
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/namejr/p/11246779.html