() Filter data according to conditions
Many times, when we get a table, we need to filter the content according to the queue contained in the table. Generally speaking, what we may think of is to traverse the content of the entire table for conditional filtering. However, this method increases the amount of code and is prone to errors, so () can solve this problem.
() Overload
**Select(); **get array of all objects;
**Select(string filterExpression); **Get an array of all objects that match the filter criteria in primary key order (if there is no primary key, in order of addition);
**Select(string filterExpression, string sort); **get an array of all objects in the specified sort order and matching the filter criteria;
**Select(string filterExpression,string sort,DataViewRowState record States); ** Get all matching the filters in the sort order and the specified state.
Give an example
Select("Results = 'PASS' ");//Filter all data in the field 'Results' as 'PASS'Select("Time>= 100 ");//Filter all data with field 'Time' greater than or equal to 100Select("Results = 'PASS' and Time>= 100 ");//Filter all data whose field ‘Results’ is ‘PASS’ and field ‘Time’ is greater than or equal to 100Select("Results = 'PASS' or Time>= 100 ");//Filter all data whose field ‘Results’ is ‘PASS’ or field ‘Time’ is greater than or equal to 100Select("Results like '%NG_%' ");//Filter field 'Results' field contains all data of the 'NG_' string
Common data filtering methods for DataTable
Computer
Filter data by conditions and perform statistical operations on the data
("Avg(height)", "age > 22 AND Name LIKE 'plum%'");
Select
Query one or more rows of data according to conditions
DataRow[] drs = ("Name is NULL");
Find
Find 1 row of data based on the primary key of DataTable, only the primary key field can be found
If the primary key is multiple fields, you need to use the Object[] array to splice it
There is only one field for the primary key
DataRow dr = ("14109");
The primary key has multiple fields
Object[] obj= new Object[]{268,"2001-7-1"}; DataRow dr = (obj);
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.