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 ">