get index of DataTable column with name

后端 未结 4 1874
遇见更好的自我
遇见更好的自我 2020-12-13 23:58

I have some code which sets the value of cells in a DataRow by column name i.e.

row[\"ColumnName\"] = someValue;

I want to also set the val

4条回答
  •  生来不讨喜
    2020-12-14 00:51

    You can simply use DataColumnCollection.IndexOf

    So that you can get the index of the required column by name then use it with your row:

    row[dt.Columns.IndexOf("ColumnName")] = columnValue;
    

提交回复
热议问题