Select method


Select method

1
2
3
Select (); 
Select (filter condition); // be filtered based on filtering criteria, such as Select ( "ColumnName1 like 'XX%%'");
Select (filter condition, sort fields); // filtered and sorting, such as Select ( "columnname1 like '% xx% '", columnname2);

Complete a query that returns a DataTable back, often we want to continue to search in the query results. Then you can use the Select method to re-query results.
Select method has four overloads, we often use is DataTable.Select(String);.

Here to talk with a parameter DataTable.Select(String):
This Stringparameter is defined query type. Equivalent to the WHERE clause in the SQL query language (excluding WHERE), in line with the syntax of SQL language syntax.
I think it is similar sql syntax only.

But I tried not support BETWEEN AND, successful examples For:

1
2
// FromTime and TOTIME DateTime are two types of variables; occurTime is dTable inside the column name;
the DataRow [] = datarows dTable.Select ( "occurTime> = '" + FromTime + "' and occurTime <= '" + + TOTIME " ' " );

The DataTable.Select () method which supports simple filtering and sorting, the conditions do not support sophisticated filtering and sorting. The string must be inside the column names and data, and>, <, =, <> relational operator and the like. A few examples:

1
2
3
DataRow[]   row   =   Detailtb.Select("WZMC='"+MaterialName+"' and   CZ='"+MaterialTexture+"   and   GG='"+MaterialSpecs+"'");    
DataTable.Select("City Like 'B%'");
DataTable.Select("name='" + a +"'");

We must pay attention to the problem of single quotes; before me is the variable in double quotes, and has been an error, and later checked the Internet and found that first double quotes and then single quotes; that is, '' variable '';

Original: Big Box  Select method


Guess you like

Origin www.cnblogs.com/petewell/p/11584839.html