Modify the value of a column in csharp able format

Source: Internet
Author: User

/// <Summary>
/// Tu juwen
/// 2012-04-14
/// </Summary>
/// <Param name = "table"> </param>
/// <Returns> </returns>
Static DataTable GetDecTable (DataTable table)
{
If (! Object. Equals (table, null ))//
{
// Foreach (DataRow myRow in thisTable. Rows ){
// Foreach (DataColumn myCol in thisTable. Columns ){
// Console. WriteLine (myRow [myCol]);
//}
 
// DataTable tablecopy = table. Copy ();
DataTable tableDec = new DataTable ();
// TableDec = table. Copy ();
// Obtain the column name and data type.
// Foreach (DataColumn column in table. Columns)
//{
// TableDec. Columns. Add (column. ColumnName, column. DataType );
//}
// Foreach (DataColumn myCol in table. Columns)
//{
// If (myCol. ColumnName = "EmployeeNo ")
//{
/// Row [myCol]
//}
// Foreach (DataRow row in table. Rows) // Loop over the rows.
//{
 
/// TableDec. Rows. Add (myRow [myCol])
//}
// String employeeNo = CryptographerUTF. GetDecryptString (row ["EmployeeNo"]. ToString ());
// String employeeName = CryptographerUTF. GetDecryptString (row ["EmployeeName"]. ToString ());
// TableDec. Rows. Add ();
//}

// Clone table structure, data record not filled
 
// TableDec = table. Clone ();

// Foreach (DataColumn gcol in datatable. Columns)
//{
// If (gcol. ColumnName = "EmployeeNo ")
//{
/// Modify the Data Type
 
// Gcol. DataType = typeof (String );
//}
//}
// Fill in data for the new table
// Foreach (DataRow row in tableDec. Rows)
//{
// DataRow nr = datatable. NewRow ();
// Nr ["EmployeeName"] = row ["EmployeeName"];
//// Modify the record
 
// Nr ["EmployeeNo"] = row ["EmployeeNo"]. toString ()";
 
// Nr ["sex"] = row ["sex"];
// Datatable. Rows. Add (nr );
//}
 
// Copy the table structure and data
TableDec = table. Copy ();
// Change the data of a specified Column
Foreach (DataRow row in tableDec. Rows)
{
// Modify the record value
 
Row ["EmployeeNo"] = CryptographerUTF. GetDecryptString (row ["EmployeeNo"]. ToString ());
// Modify the record value
Row ["EmployeeName"] = CryptographerUTF. GetDecryptString (row ["EmployeeName"]. ToString ());
 
}

 
Return tableDec;
 
}
Else
{
Return null;
}
}
 

 

From®Geovin Du Dream Park™

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.