Auto uncrement column

  • Thread starter Thread starter Adrian
  • Start date Start date
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"));
 
Back
Top