How to rename the datatable column name without losing the data?

后端 未结 4 1001
借酒劲吻你
借酒劲吻你 2021-01-12 17:41

Q:

I want to rename my data table column names .

I tried this :

dt.Columns[8].ColumnName = \"regnum\";

dt.AcceptChanges();
<
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 18:23

    dt.Columns[8].ColumnName = "regnum";
    

    This just binds your Columns[8] to the non-existing "regnum" column in the Db.

    If you want to rename the actuals Db column, execute an SQL script.

    But my guess is you actually want to change the Caption:

      dt.Columns[8].Caption = "regnum";
    

提交回复
热议问题