Click here to Skip to main content
12,998,863 members (69,437 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Rate this: bad
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");

where ds is a Dataset object.

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" ...);

Rate this: bad
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 = and #t.batch = s.batch

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

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

Solution 3

select distinct * from datatablename

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
Web01 | 2.8.170622.1 | Last Updated 11 Jun 2012
Copyright © CodeProject, 1999-2017
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