get index of DataTable column with name

后端 未结 4 1870
遇见更好的自我
遇见更好的自我 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条回答
  •  Happy的楠姐
    2020-12-14 00:39

    You can use DataColumn.Ordinal to get the index of the column in the DataTable. So if you need the next column as mentioned use Column.Ordinal + 1:

    row[row.Table.Columns["ColumnName"].Ordinal + 1] = someOtherValue;
    

提交回复
热议问题