DataTable行列转换

 #region DataTable行列转换
        /// <summary>
        /// DataTable行列转换
        /// </summary>
        /// <param name="scr">要转换的DataTable</param>
        /// <param name="columnIndex">要作为Column的那列</param>
        /// <returns></returns>
        public static DataTable DataTableColToRow(DataTable src,int columnIndex)
        {
            DataTable result = new DataTable();
            DataColumn column = src.Columns[columnIndex];
            result.Columns.Add(column.ColumnName);
            ; i < src.Rows.Count; i++)
            {
                result.Columns.Add(src.Rows[i][column].ToString());
            }

            foreach (DataColumn col in src.Columns)
            {
                if(col==column)
                {
                    continue;
                }

                ];
                newRow[] = col.ColumnName;
                ; i < src.Rows.Count; i++)
                {
                    newRow[i + ] = src.Rows[i][col];
                }
                result.Rows.Add(newRow);
            }
            return result;
        }

        /// <summary>
        ///  DataTable行列转换
        /// </summary>
        /// <param name="src">要转换的DataTable</param>
        /// <param name="columnName">要作为Column的那列</param>
        /// <returns></returns>
        public static DataTable DataTableColToRow(DataTable src,string columnName)
        {
            ; i < src.Columns.Count; i++)
            {
                if(src.Columns[i].ColumnName.ToUpper()==columnName.ToUpper())
                {
                    return DataTableColToRow(src, i);
                }
            }
            return new DataTable();
        }

        #endregion
上一篇:多线程之CEvent


下一篇:Vmware虚拟机不能使用键盘的解决方法