mercoledì 30 maggio 2012

MS: 70-516 VehicleRepairLab

Questo l'esercizio proposto alla fine della prima lezione.
Esempio decisamente banale e poco edificante.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VehicleRepairLab
{
    public partial class frmVehicleRepairLab : Form
    {
        private DataSet ds;

        public frmVehicleRepairLab()
        {
            InitializeComponent();
        }

        private void frmVehicleRepairLab_Load(object sender, EventArgs e)
        {
            CreateSchema();
        }

        private void CreateSchema()
        {
            ds = new DataSet("VehiclesRepairs");
            var vehicles = ds.Tables.Add("Vehicles");
            vehicles.Columns.Add("VIN", typeof(string));
            vehicles.Columns.Add("Make", typeof(string));
            vehicles.Columns.Add("Model", typeof(string));
            vehicles.Columns.Add("Year", typeof(int));
            vehicles.PrimaryKey = new DataColumn[] { vehicles.Columns["VIN"] };
            
            var repairs = ds.Tables.Add("Repairs");
            var pk = repairs.Columns.Add("ID", typeof(int));
            
            pk.AutoIncrement = true;
            pk.AutoIncrementSeed = -1;
            pk.AutoIncrementStep = -1;
            repairs.Columns.Add("VIN", typeof(string));
            repairs.Columns.Add("Description", typeof(string));
            repairs.Columns.Add("Cost", typeof(decimal));
            repairs.PrimaryKey = new DataColumn[] { repairs.Columns["ID"] };
            
            ds.Relations.Add(
                    "vehicles_repairs",
                    vehicles.Columns["VIN"],
                    repairs.Columns["VIN"]);
            
            MessageBox.Show("Schema created!");
        }
    }
}

MS: 70-516 Samples of chapter 1 Lesson 1 part 3

Questo l'ultima sub legata alla lezione 


static void Sample_17()
        { 
            /* MERGE data ... */
            DataSet ds = new DataSet("Colleghi");

            DataTable dCollega = ds.Tables.Add("Collega");
            dCollega.Columns.Add("IDCollega", typeof(int));
            dCollega.Columns.Add("Cognome", typeof(string));
            dCollega.Columns.Add("Nome", typeof(string));
            dCollega.PrimaryKey = new DataColumn[] { dCollega.Columns["IDCollega"] };
            dCollega.Rows.Add("1", "Arosio", "Fabio");
            dCollega.Rows.Add("2", "Eridani", "Caludio");

            DataSet dsTmp = ds.Copy();

            DataTable dCollega1 = dsTmp.Tables["Collega"];
            dCollega1.Rows.Add("3", "Arosio_A", "Fabio_B");
            dCollega1.Rows.Add("4", "Eridani_A", "Caludio_B");


            ds.Merge(dsTmp, false, MissingSchemaAction.AddWithKey);

            for (int i = 0; i < dCollega.Rows.Count; i++)
            {
                Console.WriteLine(dCollega.Rows[i][0].ToString() + " " + dCollega.Rows[i][1].ToString());
            }
        }

venerdì 18 maggio 2012

MS: 70-516 Samples of chapter 1 Lesson 1 part 2

Proseguiamo con il post, cercherò il più possibile di suddividere i lavori, anche se sto notando quando il libro sia prolisso.
static void Main(string[] args)
        {
            /* le classi disconnesse sono elemeniti cardine del framework..
             * La loro presenza risale alla versione 1.0
             * Non sono mai state dichiarate come obsolete e sono di uso diffuso.
             * 
             * la particolarità e che non sono connesse direttamente ai dati
             */

            #region 01-09
            Sample_01();

            Sample_02();

            Sample_03();

            Sample_04();

            Sample_05();

            Sample_06();

            Sample_07();

            Sample_08();

            Sample_09();
            #endregion

            Sample_10();

            Sample_11();

            Sample_12();

            Sample_13();

            Sample_14();

            Sample_15();

            Sample_16();
        }
Ed ecco i nuovi sample ...
static void Sample_10()
        {
            // Utilizzo di Data View

            //
            // il dataview consente di creare una vista 
            // logica della tabella 
            // questo implica che per una dataTable 
            // possono esiste (nessuna - una - più ) dataview.
            //
            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };

            DataRow dr1 = dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader" });
            DataRow dr2 = dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            DataRow dr3 = dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });

            // ordina per descrizione
            DataView dw_01 = new DataView(dt1);
            dw_01.Sort = "Description Desc";            

            // ordina per id
            DataView dw_02 = new DataView(dt1);
            dw_02.Sort = "ID Desc";

            // preleva solo la terza riga 
            DataView dw_03 = new DataView(dt1);
            dw_03.RowFilter = "ID >2";

            // preleva solo la riga uno e la riga 2
            DataView dw_04 = new DataView(dt1);
            dw_04.RowFilter = "Description Like '%l%'";

            // è possibil indicare in un estrazione
            // anche il tipo di dato che effettivamente 
            // vogliamo analizzare.

            DataView dw_05 = new DataView(dt1);
            dw_05.RowFilter = "Description Like '%l%'";
            dw_05.RowStateFilter = DataViewRowState.Unchanged;

        }
static void Sample_11()
        {
            // Utilizzo di Data View

            //
            // il dataview consente di creare una vista 
            // logica della tabella 
            // questo implica che per una dataTable 
            // possono esiste (nessuna - una - più ) dataview.
            //
            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };

            DataRow dr1 = dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader" });
            DataRow dr2 = dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            DataRow dr3 = dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });

            // ordina per descrizione
            DataView dw_01 = new DataView(dt1);
            dw_01.RowFilter = "Description like '%t%'";

            var buffer = new System.Text.StringBuilder();
            foreach (DataColumn dc in dw_01.Table.Columns)
            {
                buffer.AppendFormat("{0,15} ", dc.ColumnName);
            }
            buffer.Append("\r\n");
            foreach (DataRowView dr in dw_01)
            {
                foreach (DataColumn dc in dw_01.Table.Columns)
                {
                    buffer.AppendFormat("{0,15} ", dr.Row[dc]);
                }
                buffer.Append("\r\n");
            }
            Console.WriteLine(buffer.ToString());

        }
static void Sample_12()
        {
            // Utilizzo di Data View

            //
            // Esportare da un dataview ad una data table
            //
            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };

            DataRow dr1 = dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader" });
            DataRow dr2 = dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            DataRow dr3 = dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });

            // ordina per descrizione
            DataView dw_01 = new DataView(dt1);
            dw_01.RowFilter = "Description like '%t%'";


            DataTable dt2 = dw_01.ToTable("ntFromView", true, "ID", "Name", "Description");
        }
static void Sample_13()
        { 
            //
            // utilizzo del dataSet
            //

            //
            // creazione e composizione 
            // di un schema con 2 tabelle 
            // con chiave primaria e 
            // relazione.
            //
            DataSet ds = new DataSet("Colleghi");

            DataTable dTipoCollega = ds.Tables.Add("TipoCollega");
            dTipoCollega.Columns.Add("IDTipoCollega", typeof(int));
            dTipoCollega.Columns.Add("TipoCollega", typeof(string));
            dTipoCollega.Columns.Add("Descrizione", typeof(string));

            dTipoCollega.PrimaryKey = new DataColumn[]{dTipoCollega.Columns["IDTipoCollega"]};

            DataTable dCollega = ds.Tables.Add("Collega");
            dCollega.Columns.Add("IDCollega", typeof(int));
            dCollega.Columns.Add("IDTipoCollega", typeof(int));
            dCollega.Columns.Add("Cognome", typeof(string));
            dCollega.Columns.Add("Nome", typeof(string));
            dCollega.Columns.Add("Eta", typeof(string));

            dCollega.PrimaryKey = new DataColumn[] { dCollega.Columns["IDCollega"] };

            ds.Relations.Add("rCollega_Tipo", dTipoCollega.Columns["IDTipoCollega"], 
                                                dCollega.Columns["IDCollega"]);


        }
static void Sample_14()
        {
            // specializzazione di un dataset

            DataSet ds = new DataSet("Colleghi");

            DataTable dTipoCollega = ds.Tables.Add("TipoCollega");
            dTipoCollega.Columns.Add("IDTipoCollega", typeof(int));
            dTipoCollega.Columns.Add("TipoCollega", typeof(string));
            dTipoCollega.Columns.Add("Descrizione", typeof(string));

            dTipoCollega.PrimaryKey = new DataColumn[] { dTipoCollega.Columns["IDTipoCollega"] };

            DataTable dCollega = ds.Tables.Add("Collega");
            dCollega.Columns.Add("IDCollega", typeof(int));
            dCollega.Columns.Add("IDTipoCollega", typeof(int));
            dCollega.Columns.Add("Cognome", typeof(string));
            dCollega.Columns.Add("Nome", typeof(string));
            dCollega.Columns.Add("Eta", typeof(string));

            dCollega.PrimaryKey = new DataColumn[] { dCollega.Columns["IDCollega"] };

            ds.Relations.Add("rCollega_Tipo", dTipoCollega.Columns["IDTipoCollega"],
                                                dCollega.Columns["IDCollega"]);


            //
            //  accesso alle tabelle
            //

            DataTable dt01 = ds.Tables["TipoCollega"];

            //
            // questa riga risulta essere in errore
            //
            // DataTable dt02 = ds.TipoCollega;
            // 
            // per poter ovviare al problema è necesario creare 
            // uno schema XSD che consenta 
            // l'individuazione corretta della tabella as Property
            // 

        }
static void Sample_15()
        { 
            //
            // per questo esempio è necessario aggiungere 
            // al progetto un dataSet
            // al fine di ricreareare tramite editor
            // le tabelle le chiavi e la relazione 
            // progettata via codice.

            // Consolidare l'esempio tramite l'immagine in allegato.

            dsColleghi dC = new dsColleghi();

            DataTable dtc = dC.dtTipoCollega;
            DataTable dc = dC.dtCollega;

        }
static void Sample_16()
        {
            dsColleghi dC = new dsColleghi();

            DataTable dtc = dC.dtTipoCollega;
            dtc.Rows.Add("1", "Interno", "Collega a dipendeza del cliente");
            dtc.Rows.Add("2", "Esterno", "Collega a dipendeza di un fornitore");
            dtc.Rows.Add("3", "Stretto", "Collega a dipendeza del tuo stesso fornitore");


            DataTable dc = dC.dtCollega;
            dc.Rows.Add("1", "1", "Arosio", "Fabio", "38");
            dc.Rows.Add("2", "1", "Arosio", "Lorenzo", "38");
            dc.Rows.Add("3", "2", "Arosio", "Claudio", "38");


            DataRow[] Colleghi = dtc.Rows[0].GetChildRows("dtTipoCollega_dtCollega");
            foreach (DataRow dr in Colleghi)
            {
                Console.WriteLine( string.Format("Collega: {0} Tipo {1}",
                                    dr["Nome"], dtc.Rows[0]["TipoCollega"]));
            }



            DataRow Tipo = dc.Rows[1].GetParentRow("dtTipoCollega_dtCollega");
            
            Console.WriteLine( string.Format("Tipo: {0} Collega {1}",
                            Tipo["TipoCollega"], dc.Rows[1]["Nome"]));
            
        
        }

mercoledì 16 maggio 2012

MS: 70-516 Samples of chapter 1 Lesson 1 part 1

Perchè No ? Mi pare oppurtuno condividere chi come me sta affrontando questi studi. Nel mio caso sono partito proprio dall'inizio, un po' per comprendere fino a che punto sono arrivato un po' appunto per condividere quest'esperienza. Spero come sempre di essere d'aiuto.
static void Main(string[] args)
        {
            /* le classi disconnesse sono elemeniti cardine del framework..
             * La loro presenza risale alla versione 1.0
             * Non sono mai state dichiarate come obsolete e sono di uso diffuso.
             * 
             * la particolarità e che non sono connesse direttamente ai dati
             */

            Sample_01();

            Sample_02();

            Sample_03();

            Sample_04();

            Sample_05();

            Sample_06();

            Sample_07();

            Sample_08();

            Sample_09();
        }
Ho preparato i primi nove esempi, sono decisamente semplici ma permettono di comprendere quanto è proposto nel libro d'esame.
static void Sample_01()
        { 
            // Creazione di una DataTable 
            // esempio decisamente semplice

            // questa è creata senza esplicitare 
            // il nome
            DataTable dt0 = new DataTable();

            // questa è creata esplicitando il nome
            DataTable dt1 = new DataTable("NewDataTable");


            Console.WriteLine("dt0 Name:" + dt0.TableName);
            Console.WriteLine("dt1 Name:" + dt1.TableName);
        }
static void Sample_02()
        { 
            // aggiungere una o più colonne ad una 
            // datatable
            
            DataTable dt1 = new DataTable("NewDataTable");

            //
            // per ogni colonna è necessario 
            // esplicitare la definizione
            // al fine di creare uno schema
            // 

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int); // indica il tipo della colonna
            dc0.AllowDBNull = false;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string); 
            dc1.MaxLength = 50;  // indica la lunghezza massima del campo
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true; // indica che potrà contenere un null value
            dt1.Columns.Add(dc2);



            Console.WriteLine("dt1 Name:" + dt1.TableName +" has columns:");
            for (int i = 0; i < dt1.Columns.Count; i++)
            {
                Console.WriteLine("Column Name:" + dt1.Columns[i].ColumnName);
            }
        }
static void Sample_03()
        {
            // aggiungere una chiave primaria alla
            // datatable

            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int); 
            dc0.AllowDBNull = false;
            //
            // indichiamo che la colonna ID 
            // sarà un auto increment
            // -specificando il "quanto" per l'incremento dc0.AutoIncrementStep
            // -specificando il "partendo da :"  dc0.AutoIncrementSeed
            //
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;

            dt1.Columns.Add(dc0);


            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;  
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true; 
            dt1.Columns.Add(dc2);

            //
            // aggiungiamo la collonna all' array dell colonne chiave.
            // Questo campo è dato da una o più colonne
            // in modo da poter considerare anche chiavi complesse.
            // 
            dt1.PrimaryKey = new DataColumn[] { dc0 };
        }
static void Sample_04()
        {
            // aggiungere una o più righe 
            // ossia aggiungere una o più DataRow

            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };


            dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader"});
            dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });

        }
static void Sample_05()
        {
            // Osservare gli stati di una dataRow
            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = true;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };

            //
            // esempi di cambiamento di stato di una
            // DataRow
            //
            DataRow dr = dt1.NewRow();
            Console.WriteLine("Row State " + dr.RowState);

            dt1.Rows.Add(dr);            
            Console.WriteLine("Row State " + dr.RowState);

            dr["Name"] = "Fabio";
            Console.WriteLine("Row State " + dr.RowState);

            dt1.AcceptChanges();
            Console.WriteLine("Row State " + dr.RowState);

            dr["Name"] = "Claudio";
            Console.WriteLine("Row State " + dr.RowState);

            dt1.RejectChanges();
            Console.WriteLine("Row State " + dr.RowState);

            dr["Name"] = "Claudio";
            Console.WriteLine("Row State " + dr.RowState);
            dt1.AcceptChanges();

            dr.Delete();
            Console.WriteLine("Row State " + dr.RowState);
            dt1.AcceptChanges();
        }
static void Sample_06()
        {
            // verificare la versione di ogni riga.

            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };


            dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader" });
            dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });


            DataRow dr = dt1.Rows[1];

            dr["Name"] = "Claudio";

            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                foreach (string versionString in Enum.GetNames(typeof(DataRowVersion)))
                {
                    DataRowVersion version = ( DataRowVersion)Enum.Parse( typeof(DataRowVersion), versionString);

                    if (dt1.Rows[i].HasVersion(version))
                    {
                        Console.WriteLine(string.Format( "Version: {0} Value: {1} \r\n", version, dt1.Rows[i]["Name", version]));
                    }
                }
            }
        }
static void Sample_07()
        {
            // Due metodi importanti di DataRow

            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };


            DataRow dr1 = dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader" });
            DataRow dr2 = dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            DataRow dr3 = dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });

            dt1.AcceptChanges();

            // imposta la riga come AGGIUNTA
            if (dr1.RowState == DataRowState.Unchanged)
            {
                dr1.SetAdded();
                Console.WriteLine("Row State " + dr1.RowState);
            }

            if (dr2.RowState == DataRowState.Unchanged)
            {
                // imposta la riga come MODIFICATA                
                dr2.SetModified();
                Console.WriteLine("Row State " + dr2.RowState);
            }
        }
static void Sample_08()
        {
            // Clone / Copy di una DataTable

            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };

            DataRow dr1 = dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader" });
            DataRow dr2 = dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            DataRow dr3 = dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });

            // esegue la copia della tabella
            DataTable dt2 = dt1.Copy();

            // esegue il colone della tabella
            DataTable dt3 = dt1.Clone();

            dt1.Rows[0][1] = "Demo";

            Console.WriteLine("DT1 :" + dt1.Rows[0][1]);
            Console.WriteLine("DT2 :" + dt2.Rows[0][1]);

            dt2.Rows[0][1] = "Test";

            Console.WriteLine("DT1 :" + dt1.Rows[0][1]);
            Console.WriteLine("DT2 :" + dt2.Rows[0][1]);


            if (dt3.Rows.Count > 0)
            {
                Console.WriteLine("DT3 :" + dt3.Rows[0][1]);
            }
        }
static void Sample_09()
        {
            // Clone / Copy di una DataTable e delle sue righe

            DataTable dt1 = new DataTable("NewDataTable");

            DataColumn dc0 = new DataColumn("ID");
            dc0.DataType = typeof(int);
            dc0.AllowDBNull = false;
            dc0.AutoIncrement = true;
            dc0.AutoIncrementStep = 1;
            dc0.AutoIncrementSeed = 1;
            dt1.Columns.Add(dc0);

            DataColumn dc1 = new DataColumn("Name");
            dc1.DataType = typeof(string);
            dc1.MaxLength = 50;
            dc1.AllowDBNull = false;
            dt1.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description");
            dc2.DataType = typeof(string);
            dc2.MaxLength = 150;
            dc2.AllowDBNull = true;
            dt1.Columns.Add(dc2);

            dt1.PrimaryKey = new DataColumn[] { dc0 };

            DataRow dr1 = dt1.Rows.Add(new object[] { 1, "Fabio", "Team Leader" });
            DataRow dr2 = dt1.Rows.Add(new object[] { 2, "Fabio", "Developer" });
            DataRow dr3 = dt1.Rows.Add(new object[] { 3, "Fabio", "Tester" });

          
            // esegue il colone della tabella
            DataTable dt2 = dt1.Clone();

            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                dt2.ImportRow(dt1.Rows[i]);
            }

        }