我从数据集中的表列值中检索唯一值 [英] i retriving unique values from table column values in the dataset
本文介绍了我从数据集中的表列值中检索唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据集,其中一个表是他们的
表列值重复
i希望从表列值中获取唯一值
不是来自后端我想用c#
$执行此操作b $ b
任何人都可以告诉我代码吗?
操作前 -
用户ID
-------
1
2 >
33
33
55
67
$
手术后 -
结果
------
1
2
33
55
67
i have a dataset in that one table is their
table column values are repeated
i want to get the unique values from table column values
not from backend i want to perform this operation using c#
can any one tell me the code ?
before operation -
user id
-------
1
2
33
33
55
67
67
after operation -
result
------
1
2
33
55
67
推荐答案
还有一种简单的方法,它看起来像这样:
DataSet ds; //您拥有的数据集
DataTable dt; //仅包含不同数据的目标数据表
dt = ds.Tables [0] .DefaultView.ToTable(true,[list of columns]);
希望它有所帮助。
There is an another simple way of doing it, it would look something like this:
DataSet ds; // The data set that you have
DataTable dt; // The target data table with only distinct data
dt=ds.Tables[0].DefaultView.ToTable(true,[list of columns]);
Hope it helps.
使用以下查询
SELECT DISTINCT userid FROM table_name
我很抱歉,这是不正确的答案。
你可以用例如LINQ实现了一个独特的列表。例如,如果字段为字符串,则数据类型如下所示:
You can use for example LINQ to achieve a distinct list. For exammple something like the following if the datatype if the field is string:
Dim query = (From item In datatablename.AsEnumerable
Select item.Field(Of String)("FieldNameInDataTable")).Distinct
请记住
Just remember
这篇关于我从数据集中的表列值中检索唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文