Being simple

Any fool can write code that computer can understand. Good programmers write codes that humans can understand.

导航

公告

统计

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];
        }
    }

posted on 2008-10-08 21:38 margiex 阅读(56) 评论(0) 编辑 收藏