Click here to Skip to main content
12,446,525 members (57,549 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# .NET
i have the read the some value from the database in data Table in C#.NET.
in this datatable the following value contains
batch  tag     pcdatelogged
1      11   12-12-2012 11:35
1      12   12-12-2012 11:36
1      13   12-12-2012 11:37
1      14   12-12-2012 11:38
2      15   12-12-2012 11:39
2      16   12-12-2012 11:40
2      17   12-12-2012 11:41
2      18   12-12-2012 11:42
i want to select the distinct values from the datatable & display into the grid
batch  tag(last value)   pcdatelogged(min)   pcdatelogged(max)
1           14           12-12-2012 11:35    12-12-2012 11:38
2           18           12-12-2012 11:39    12-12-2012 11:42
i want the above output in the grid


Thanks in advance
Posted 30-Dec-11 18:25pm
Updated 30-Dec-11 18:29pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi vrushali,
Try this code, i think it'll be helpful for you.

ds.Tables["datatablename"].DefaultView.ToTable(true, "batch"); 
dt.DefaultView.ToTable(true, "batch");

Quote:
where ds is a Dataset object.


Regards,
Bluesathish
  Permalink  
Comments
vrushali katkade 31-Dec-11 1:08am
   
thanks for the replay ,what about another columns, its only distinct the batch column
bluesathish 31-Dec-11 1:12am
   
Then try this one,
DataView view = new DataView(table);
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...);

ref: http://stackoverflow.com/questions/1199176/how-to-select-distinct-values-from-datatable
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Here is one solution :

if OBJECT_ID('tempdb..#t') is not null
  drop table #t
select  * , ROW_NUMBER() over ( partition by batch order by batch, tag) no  into #t from  events
 
select s.batch, tag, min , max from 
(select max(no) no, MIN(pcdatelogged) min , MAX(pcdatelogged) max , batch from #t group by batch) s
join #t on #t.no = s.no and #t.batch = s.batch


Convert it to a stored procedure and retrieve data with a suitable datasource.

Hope it helps.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

select distinct * from datatablename
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 11 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100