C# – How to change the DataTable Column Name

ado.netasp.netcdatatable

I have one DataTable which has four columns such as

 StudentID        CourseID          SubjectCode            Marks    
------------     ----------        -------------          --------
    1               100              MT400                  80
    2               100              MT400                  79
    3               100              MT400                  88

Here I am inserting this Datatable into the Sql server table by passing this datatable as an XML Table.

I just want to Change the DataTable Column Name "Marks" as "SubjectMarks" and pass this DataTable as an XML Table.

I know how to pass the DataTable as an XML Table. But I dont know, How to change the DataTable Column Name "Marks" as "SubjectMarks".

Best Answer

Try this:

dataTable.Columns["Marks"].ColumnName = "SubjectMarks";