Solved

DataTable  Increment

Posted on 2011-03-08
1
431 Views
Last Modified: 2012-05-11
how do i adding identity column to datatable?

i want it to Increment by 1 each time i enter a row in.


here is the sample code that i have coded in c#:

        DataTable dt = new DataTable();

        dt.Columns.Add("DomainNames");
        dt.Columns.Add("Status");
        dt.Columns.Add("Delete");
        dt.Columns.Add("Enabled");
        dt.Columns.Add("Index");


This creates columns

i want it to auto Increment by 1 each time i enter a row in.

0
Comment
Question by:JCWEBHOST
1 Comment
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
Comment Utility
To add auto increment column in the DataTable, we can set the AutoIncrement property of the DataColumn object as true and specify the seed value after adding that field into the DataTable object.


// create columns for the DataTable
DataTable dTable =  new DataTable();
DataColumn auto = new DataColumn("AutoID", typeof(System.Int32));
dTable.Columns.Add(auto);
// specify it as auto increment field
auto.AutoIncrement = true;
auto.AutoIncrementSeed = 1;
auto.ReadOnly = true;


Source: http://www.dotnetfunda.com/interview/exam545-how-to-add-auto-increment-column-in-the-datatable-.aspx
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now