using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Column A");
tbl.Columns.Add("Column B");
tbl.Columns.Add("Column C");
tbl.Columns.Add("Column D");
tbl.Columns.Add("Column E");
Console.WriteLine("Before Change...");
PrintColumnsName(tbl);
foreach (DataColumn dcl in tbl.Columns)
{
if (dcl.ColumnName.Contains(" "))
{
dcl.ColumnName = dcl.ColumnName.Replace(" ", "");
}
}
tbl.AcceptChanges();
Console.WriteLine("After Change...");
PrintColumnsName(tbl);
Console.WriteLine("Press a key to quit...");
Console.ReadKey();
}
static void PrintColumnsName(DataTable t)
{
foreach (DataColumn dcl in t.Columns)
{
Console.WriteLine(dcl.ColumnName);
}
}
}
}