Pages

Monday, August 19, 2013

Create Datatable manually-ASP.Net

Add Red Code to Create DataTable, change the columns name and Datatype according to your needs.

  // Initialise Datatable

        DataTable dt = new DataTable( );      

// add columns with their Datatypes

        dt.Columns.Add("Id", Type.GetType("System.Decimal"));                    // decimal type
        dt.Columns.Add("Country_ID", Type.GetType("System.String"));          // string type
        dt.Columns.Add("Name", Type.GetType("System.String"));
        dt.Columns.Add("Description", Type.GetType("System.String"));
        dt.Columns.Add("Url", Type.GetType("System.String"));
        dt.Columns.Add("Unique Url Name", Type.GetType("System.String"));
        dt.Columns.Add("Meta Title", Type.GetType("System.String"));
        dt.Columns.Add("Meta Keyword", Type.GetType("System.String"));
        dt.Columns.Add("Meta Description", Type.GetType("System.String"));



Details:

The below line is used to add a column with the Datatype:
dt.Columns.Add("Column_name", Type.GetType("System.DataType_name"));

No comments:

Post a Comment