Selecting Dataset records

G

Guest

Hey all,

Is there a way to get similar functionality as the SELECT DISTINCT records
in a SQL Statement when selecting records from a dataset?

thanks,
rodchar
 
G

Guest

Hey I have question about the code. Why use Object as data type for
LastValue? Very new to objects.

Public Function SelectDistinct(ByVal TableName As String, ByVal
SourceTable As DataTable, ByVal FieldName As String) As DataTable
Dim dt As New DataTable(TableName)
dt.Columns.Add(FieldName, SourceTable.Columns(FieldName).DataType)

Dim LastValue As Object = Nothing
Dim dr As DataRow
For Each dr In SourceTable.Select("", FieldName)
If LastValue Is Nothing Or Not ColumnEqual(LastValue,
dr(FieldName)) Then
LastValue = dr(FieldName)
dt.Rows.Add(New Object() {LastValue})
End If
Next dr
If Not (ds Is Nothing) Then
ds.Tables.Add(dt)
End If
Return dt
End Function 'SelectDistinct
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top