DataColumn Name from DataRow (not DataTable)

后端 未结 4 1845
暗喜
暗喜 2020-12-30 18:23

I need to iterate the columnname and column datatype from a specific row. All of the examples I have seen have iterated an entire datatable. I want to pass a single row to a

4条回答
  •  情深已故
    2020-12-30 19:21

    You can make it easier in your code (if you're doing this a lot anyway) by using an extension on the DataRow object, like:

    static class Extensions
    {
        public static string GetColumn(this DataRow Row, int Ordinal)
        {
            return Row.Table.Columns[Ordinal].ColumnName;
        }
    }
    

    Then call it using:

    string MyColumnName = MyRow.GetColumn(5);
    

提交回复
热议问题