Create Datatable dynamically in ASP.Net

Create Datatable dynamically in ASP.Net, How set the Increment Seed, Unique, Primary key, Create columns of int, String, boolean type.

     private void createTable()
        {
            if (Session["dt"] == null)
            {
                dt = new DataTable("OrderInfo");
            }
            else
            {
                Session["dt"] = null;
                dt = new DataTable("OrderInfo");
            }
            DataColumn dc1 = new DataColumn("Id", typeof(System.Int32));
            dc1.AutoIncrement = true;
            dc1.AutoIncrementSeed = 1;
            dc1.ReadOnly = true;
            dc1.Unique = true;
            dt.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn("Description"); dc2.DataType = System.Type.GetType("System.String");
            dt.Columns.Add(dc2);

            DataColumn dc3 = new DataColumn("Quantity");
            dc3.DataType = System.Type.GetType("System.Int32");
            dt.Columns.Add(dc3);

            DataColumn dc4 = new DataColumn("price");
            dc4.DataType = System.Type.GetType("System.Decimal");
            dt.Columns.Add(dc4);

            DataColumn dc5 = new DataColumn("Total");
            dc5.DataType = System.Type.GetType("System.Decimal");
            dt.Columns.Add(dc5);

            DataColumn dc6 = new DataColumn("OrderId");
            dc6.DataType = System.Type.GetType("System.Int32");
            dt.Columns.Add(dc6);

            DataColumn dc7 = new DataColumn("SrNumber");
            dc7.DataType = System.Type.GetType("System.Int32");
            dt.Columns.Add(dc7);

            Session["dt"] = dt;
        }
  

Related Alrticles

FREE!!! Registration