using System;
using System.Data;
class Program
{
static void Main(string[] args)
{
DataTable dt = new DataTable();
DataColumn col1 = dt.Columns.Add();
col1.ColumnName= "First Column";
col1.DataType = typeof(int);
col1.DefaultValue = 0;
col1.Unique = true;
col1.AllowDBNull = false;
DataColumn col2 = new DataColumn();
col2.ColumnName = "Second Column";
col2.DataType = typeof(string);
col2.MaxLength = 50;
dt.Columns.Add(col2);
dt.Columns.Add("Column-3", typeof(string)).MaxLength = 50;
DataColumn col4 = new DataColumn("Column-4");
DataColumn col5 = new DataColumn("Column-5", typeof(int));
dt.Columns.AddRange(new DataColumn[] { col4, col5 });
Console.WriteLine("DataTable has {0} DataColumns named:",dt.Columns.Count);
foreach (DataColumn col in dt.Columns)
Console.WriteLine("\t{0}", col.ColumnName);
}
}
|