Setting a column not to be nullable for a Datatable

Posted by Puneet20884 under C# category on | Views : 4085
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.AllowDBNull = false; // by default true , we can set false for not allowing nulls in it
dc.AutoIncrementSeed = 1;
dc.AutoIncrementStep = 1;
dc.Unique = true;
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