Copy codeThe Code is as follows:
/// <Summary>
/// DataTable 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 ++)
{// Set the header
Dt. Columns. Add (dtable. Rows [I] [head]. ToString ());
}
For (int k = 0; k <dtable. Columns. Count; k ++)
{
String temcol = dtable. Columns [k]. ToString ();
If (dtable. Columns [k]. ToString (). ToLower ()! = Head) // filter out the columns that set the header
{
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;
}