简体   繁体   中英

Is there a way to filter DataTable by distinct entries?

I have a datatable that has x amount of unique entries in column A. I want to be able to use DataTable.Select() to get each name in column A once. I couldn't seem to find any type of SQL equivalent of Distinct in the microsoft docs. Any help would be appreciated.

I have a DataTable that has 6 columns. I want to pull each unique entry in column 1 and store the row like this DataRow[] rows = DataTable.Select("expression here"); I then want to iterate through each row and set the values to an x-axis on a chart. Like so...

for(int i = 0; i < rows.Length; i++)
{
    string id = rows[i]["USER_ID"].ToString();
}

There is a typo in @jdweng's comment. The correct answer should be:

dataTable.AsEnumerable().Select(row => row["USER_ID"]).Distinct().ToArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM