Selecting Dataset records

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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

Similar Threads

esitmate for dataset weight 5
help with datasets 2
the best way to do this 1
user control needs data 5
datarowview vs datarow 1
Show "No Records Found" Message 1
printing my web page 1
session state 1

Back
Top