// Create a new DataColumn object DataColumn column = new DataColumn(); // Set the column name column.ColumnName = "EmployeeName"; // Set the data type column.DataType = typeof(string); // Set any additional properties column.MaxLength = 50; column.AllowDBNull = false;
// Create a new DataTable object DataTable table = new DataTable(); // Create a new DataColumn object and add it to the table DataColumn column = table.Columns.Add("EmployeeAge", typeof(int)); // Set any additional properties column.AutoIncrement = true; column.AutoIncrementSeed = 1; column.AutoIncrementStep = 1;In both examples, the global::System.Data.DataColumn class is used to create a new column for a DataTable object. Properties such as ColumnName, DataType, MaxLength, AllowDBNull, AutoIncrement, AutoIncrementSeed, and AutoIncrementStep are set to configure the column as needed.