Auto uncrement column

A

Adrian

Im am trying to create an auto increment column in a table.
Where in the code below, should I make which changes
in order to do that?

Adrian

/*
dt.Columns.Add("Key", System.Type.GetType("System.Int32"));
dt.Columns["Key"].AutoIncrement = true;
dt.Columns["Key"].AutoIncrementSeed = 1;
dt.Columns["Key"].AutoIncrementStep = 1;
dt.PrimaryKey = new DataColumn[] { dt.Columns["Key"]};
*/

DataColumn auto = dt.Columns.Add("Key", typeof(int));
dt.Columns["Key"].AutoIncrement = true;
dt.Columns["Key"].AutoIncrementSeed = 1;
dt.Columns["Key"].AutoIncrementStep = 1;

//auto.AutoIncrement = true;
//auto.AutoIncrementSeed = 0;
//auto.AutoIncrementStep = 15;

dt.PrimaryKey = new DataColumn[] {auto};

dt.Columns.Add("ForeName",
System.Type.GetType("System.String"));
dt.Columns.Add("LastName",
System.Type.GetType("System.String"));
dt.Columns.Add("TelephoneNumber",
System.Type.GetType("System.String"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top