DataTable Select Method: Filtering and Retrieving Data
The Select method in DataTable allows you to filter and retrieve data from a DataTable based on a specified criteria. It returns an array of DataRow objects that match the selection criteria.
The syntax for using the Select method is as follows:
DataRow[] rows = dataTable.Select('criteria');
where 'criteria' is a string expression that specifies the selection criteria. The criteria can be any valid SQL-like expression which includes operators, boolean operators, and functions. For example, the following criteria select all rows where the value in the 'Name' column is equal to 'John':
DataRow[] rows = dataTable.Select('Name = 'John'');
You can also use parameters in the criteria expression by using the '@' character followed by the parameter name. For example, the following criteria select all rows where the value in the 'Age' column is greater than a specified value:
int age = 30;
DataRow[] rows = dataTable.Select('Age > @age', $'age = {age}');
Note that the Select method does not modify the original DataTable, but returns a new array of DataRow objects that satisfy the selection criteria.
原文地址: https://www.cveoy.top/t/topic/noGH 著作权归作者所有。请勿转载和采集!