Groups | Blog | Home
all groups > vb.net data > april 2007 >

vb.net data : Select Distinct on a DataTable


Kerry Moorman
4/18/2007 9:16:47 AM
Doug,

Can't you just get the database to give you what you need?

Kerry Moorman


[quoted text, click to view]
Cor Ligthert [MVP]
4/18/2007 7:11:51 PM
Doug

You know that it is a standard overloaded method from 2.0

Cor

"Doug Bell" <dug@bigpond.com> schreef in bericht
news:uADgWgdgHHA.2432@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

Doug Bell
4/19/2007 12:00:00 AM
Cor, Please enlighten me.

[quoted text, click to view]

Cor Ligthert [MVP]
4/19/2007 12:00:00 AM
http://msdn2.microsoft.com/en-us/library/h2b6ehaa.aspx


"Doug Bell" <dug@bigpond.com> schreef in bericht
news:O91LyvhgHHA.3412@TK2MSFTNGP02.phx.gbl...
[quoted text, click to view]

Doug Bell
4/19/2007 12:57:22 AM
Hi,

I have a DataSet with a DataTable that has a number of duplicate rows
(except for one column that has a unique value).

Each row has OrderNo, OrderLineNo, etc and there are multiple rows with
the same OrderNo and OrderLineNo.

I need to display data in a DataGrid but displaying only one record for each
OrderNo OrderLineNo.

I was thinking about constructing a new DataTable holding the Unique
OrderNo-OrderLineNo records, something along the lines of code below but I
need to have the data ordered by 2 columns to do that.

Any ideas or suggestions?

Thanks, Doug

Dim dt as DataTable = New DataTable
dt = dsMyDataSet.Tables("MyDataTable").Clone
Dim dr, drNew as DataRow
Dim drs() as DataRow = dsMyDataSet.Tables("MyDataTable").Select("PickList =
" & PickListNo, "OrderNo ASC") 'How can I sort on 2 Columns OrderNo and
OrderLineNo
Dim iOrd, iOrdLin as Integer
Dim iCol as integer
dim iCols as integer = dt.Columns.Count-1

for each dr in drs
If iOrd <> dr("OrderNo") and iOrdLin <> dr("OrderLineNo") Then
drNew = dt.NewRow
For iCol = 0 to iCols
drNew(iCol) = dr(iCol)
Next iCol
dt.Rows.Add(drNew)
Else
iOrd = dr("OrderNo")
iOrdLin <> dr("OrderLineNo")
End If

next dr

Doug Bell
4/19/2007 2:38:17 AM
I would have if I could.

The duplicate records are required.

[quoted text, click to view]

Doug Bell
4/19/2007 2:39:08 AM
I solved the problem using a DataView to create the new Table.


[quoted text, click to view]

Doug Bell
5/2/2007 10:17:39 PM
Thank you Cor

[quoted text, click to view]

AddThis Social Bookmark Button