Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 8-Sep-11 19:22pm
v2

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.
 
Share this answer
 
v3
Comments
[no name] 9-Sep-11 2:31am    
Nice one :)
Use below query
SELECT DISTINCT userid FROM table_name


I am so sorry, this is not correct answer.
 
Share this answer
 
v2
Comments
Srinivas Kumar Pasumarthi 9-Sep-11 1:21am    
not from backend i want to perform this operation using c#
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:
VB
Dim query = (From item In datatablename.AsEnumerable
             Select item.Field(Of String)("FieldNameInDataTable")).Distinct

Just remember
 
Share this answer
 
var sc = MyCollection.GroupBy(m => m.EndDate).Select(g => g.First());

For more details visit on below link.
http://www.code-sample.com/2014/06/distinct-values-from-list-using-linq.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900