1. Remove duplicate values from DataSet. The effect is similar to that of distinct in SQL. The DefaultView. ToTable method is used.
Code: the implementation function is to retrieve non-repeated values from the "distinct" column in dt
DataTable result = dt.Tables[0].DefaultView.ToTable(true, "jh");
| DataView. ToTable method (Boolean, String []) |
|
Create and return a new able Based on the rows in the existing DataView.
Namespace:System. Data
Assembly:System. Data in System. Data. dll) syntax VBC # C ++ F # JScript Printing
Public DataTable ToTable (bool distinct, params string [] columnNames)
Parameters
-
Distinct
-
Type: System. Boolean
If true, the returned DataTable will contain rows with different values for all columns. The default value is false.
-
ColumnNames
-
Type: System. String []
A string array that contains the list of column names to be included in the returned DataTable. DataTable contains the specified columns in the same order as these columns in the array.
Return Value Type: System. Data. DataTable
A new able instance contains the requested rows and columns.
2. Filter by conditions from DataSet
string strFilter = "jh='" + item + "'";DataRow[] dr = dt.Tables[0].Select(strFilter);
Appendix: DataTable. Select method (String) |
|
Returns an array of all DataRow objects that match the filtering conditions.
Namespace:System. Data
Assembly:System. Data in System. Data. dll) syntax VBC # C ++ F # JScript Printing
Public DataRow [] Select (string filterExpression)
Parameters
-
FilterExpression
-
Type: System. String
The condition used to filter rows.
Return Value Type: System. Data. DataRow []
Array of DataRow objects.