DataSet Data Filtering

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.