Setting a column to be unique for a Datatable

Posted by Puneet20884 under C# category on | Views : 1528
The sample self explanatory code goes as:

  DataTable dt = new DataTable("News");
DataColumn dc = new DataColumn("id", Type.GetType("System.String"));
dc.AutoIncrement = true;
dc.AutoIncrementSeed = 1;
dc.AutoIncrementStep = 1;
dc.Unique = true; // Unique only always !!
dt.Columns.Add("DateAdded", Type.GetType("System.String"));
dt.Columns.Add("Description", Type.GetType("System.String"));
dt.Columns.Add("OnHome", Type.GetType("System.Boolean"));

Comments or Responses

Login to post response