zoukankan      html  css  js  c++  java
  • swap two datarows in datatable

    void SwapDataRow(ref DataTable dt, int srcIndex, int dstIndex)
        {
            DataRow tmpRow = dt.NewRow();
            // backup src row
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                tmpRow[i] = dt.Rows[srcIndex][i];
            }

            // assign to src row
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                dt.Rows[srcIndex][i] = dt.Rows[dstIndex][i];
            }

            // assign to dst row
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                dt.Rows[dstIndex][i] = tmpRow[i];
            }
        }

  • 相关阅读:
    C#_Assembly-Reflection_程序集与反射
    C#_event_事件
    C#_扩展方法
    C#_Delegate_泛型
    C#_正则表达式
    C#_序列化
    Unity_ClickToShow_FadeInAndOut
    RecordToday
    写作技巧
    高效休息法
  • 原文地址:https://www.cnblogs.com/margiex/p/1306622.html
Copyright © 2011-2022 走看看