How to return datatable by executing able. Select ("condition") in datatable

Source: Internet
Author: User

In actual programming projects, we often encounter the following situation: datatable is not in the database, or datatable has not been written to the database, or the able read from the database has been changed locally, I have not written it back to the database (other changes may be required). In these cases, I only need to use it. the powerful functions of the dataview class provided by the net class library (mainly using its rowfilter attribute) can easily solve such query problems.
Some netizens asked online how to execute able. Select ("condition") in datatable to return the datatable. Today I am here to provide a solution for your reference:
CodeAs follows:

  /**/ ///   <Summary>
/// Execute the query in the datatable to return the new datatable
///   </Summary>
///   <Param name = "DT"> Source data datatable </Param>
///   <Param name = "condition"> Query Conditions </Param>
///   <Returns> </returns>
Private Datatable getnewdatatable (datatable DT, String Condition)
{
Datatable newdt =   New Datatable ();
Newdt = DT. Clone ();
Datarow [] Dr = DT. Select (condition );
For ( Int I = 0 ; I < Dr. length; I ++ )
{
Newdt. importrow (datarow) Dr [I]);
}  
Return Newdt; // Returned query results
}

Padding-left: 3px; padding-Right: 5px; "class =" noprint ">

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.