Resources » Code Snippets » ADO.NET

How to Add Auto Increment Column to DataSet

Updated: Category: ADO.NET
Author: Member Level: GoldPoints: 10

Hello, below was the method to add Auto Increment Column to DataSet

public static DataSet GetDataTableAutoIncrement ( DataTable dataTableObject, string columnName )
DataTable dataTable = new DataTable ( dataTableObject.TableName );
DataColumn dataColumn = new DataColumn ( columnName, Type.GetType ( "System.Int32" ) );
dataColumn.AutoIncrement = true;
dataColumn.AutoIncrementSeed = dataColumn.AutoIncrementStep = 1;
dataTable.Columns.Add ( dataColumn );
DataTableReader dataTableReader = new DataTableReader ( dataTableObject );
dataTable.Load ( dataTableReader );
DataSet dataSet = new DataSet ();
dataSet.Tables.Add ( dataTable );
return dataSet;

Siva Prasad Palaparthi
Software Engineer.

Did you like this resource? Share it with your friends and show your love!

Responses to "How to Add Auto Increment Column to DataSet"
Author: Joshua Riddle  20 Oct 2010   Member Level: Bronze   Points : 1
Excellent information...This was exactly what i was looking for. It allowed be to take a table from a poorly designed DB with no primary key and add one dynamically. Making my coding job a lot easier.


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India