---
title: "Add identity column in Datatable in C#"  
description: "DataTable dt = new DataTable(;);            DataColumn dcID = new DataColumn(&amp;quot;ID&amp;quot;, typeof(int));          dcID.AutoIncrement = true;"  
author: "AVADHESH PATEL"  
published: 2012-08-01  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/329/add-identity-column-in-datatable-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Add identity column in Datatable in C#

Below [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) which will [add](https://www.mindstick.com/forum/448/how-to-add-advertisement-functionalities-in-asp-dot-net-page) an [Identity column](https://www.mindstick.com/forum/103/how-to-insert-data-in-identity-column) in [DataTable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net).\

```
DataTable dt = new
DataTable("Information");        DataColumn dcID = new
DataColumn("ID",
typeof(int));       
dcID.AutoIncrement = true;        dcID.AutoIncrementSeed = 1;       
dcID.AutoIncrementStep = 1;        // Add identity column to datatable       
dt.Columns.Add(dcID);       
dt.Columns.Add("FirstName");
// Other columns       
dt.Columns.Add("LastName");       
dt.Columns.Add("Age");

       
dt.Columns.Add("Gender");
```

Adding new [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) in Datatable

```
dr["FirstName"]
= "Avadhesh";        dr["LastName"]
= "Patel";        dr["Age"] = 24;        dr["Gender"] = "Male";
       
dt.Rows.Add(dr);
```

The above code will add a new row with the ID = 1.\
\

---

Original Source: https://www.mindstick.com/blog/329/add-identity-column-in-datatable-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
