Friday, 2 November 2018

Add / Insert Identity column to DataTable in asp.net C#

////////////////////


DataTable dt = new DataTable();

        //Add columns to DataTable.
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });

        //Set AutoIncrement True for the First Column.
        dt.Columns["Id"].AutoIncrement = true;

        //Set the Starting or Seed value.
        dt.Columns["Id"].AutoIncrementSeed = 1;

        //Set the Increment value.
        dt.Columns["Id"].AutoIncrementStep = 1;

        //Add rows to DataTable.
        dt.Rows.Add(null, "Raja", "India");
        dt.Rows.Add(null, "Ram", "US");
        dt.Rows.Add(null, "Mohan", "UK");
        dt.Rows.Add(null, "Ray", "Russia");
        dt.Rows.Add(null, "Jai", "China");



No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...