DataTable row-to-column, datatable-to-Column

Source: Internet
Author: User

DataTable row-to-column, datatable-to-Column

/// <Summary> /// able row-to-column conversion // </summary> /// <param name = "dtable"> table to be converted </param>/ // <param name = "head"> convert the table header to the old table field (in lower case) </param> // <returns> </returns> public static DataTable DataTableRowtoCon (DataTable dtable, string head) {DataTable dt = new DataTable (); dt. columns. add ("NumberID"); for (int I = 0; I <dtable. rows. count; I ++) {// sets the header dt. columns. add (dtable. rows [I] [head]. toString ();} for (I Nt k = 0; k <dtable. columns. count; k ++) {string temcol = dtable. columns [k]. toString (); if (dtable. columns [k]. toString (). toLower ()! = Head) // filter out the columns {DataRow new_dr = dt. newRow (); new_dr [0] = dtable. columns [k]. toString (); for (int j = 0; j <dtable. rows. count; j ++) {string temp = dtable. rows [j] [k]. toString (); new_dr [j + 1] = (Object) temp;} dt. rows. add (new_dr) ;}} return dt ;}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.