RenameColumn

public static void RenameColumn(this System.Data.DataTable dt, string oldName, string newName)
{
    if (dt != null && !string.IsNullOrEmpty(oldName) && !string.IsNullOrEmpty(newName) && oldName != newName)
    {
        int idx = dt.Columns.IndexOf(oldName);
        dt.Columns[idx].ColumnName = newName;
        dt.AcceptChanges();
    }
}
Example:
// Consider that dataSetName is the DataSet that contains a DataTable
dataSetName.Tables[0].RenameColumn("Column1", "Name");
dataSetName.Tables[0].RenameColumn("Column2", "Email");
dataSetName.Tables[0].RenameColumn("Column3", "RegistrationDate");

Description

Rename a code that allows only stating the current name column and a new name.

Details

Double click on the code to select all.

 

;