How to change the DataTable Column Name?

thevan picture thevan · Jun 20, 2011 · Viewed 222.9k times · Source

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".

Answer

Moon picture Moon · Jun 20, 2011

Try this:

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