Create new DataSet from Existing DataSet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DataSet1 which I want to use as a source to create another DataSet2 using a sql like "Select Distinct a, b from DataSet1 ". Is this possible, and if so, can you point me in the right direction on how it should be done

Thanks
 
Hi Dchilman,

Have a look at this generic example I once made for this newsgroup, but test
it very good, I never used it.

And when it works, give a message, than I know?

Cor

Me.DataGrid1.DataSource = mydistinct.distinct(dt, "elem1")

End Class
Public Class Selectclass
Public Function distinct(ByVal dt As DataTable, _
ByVal dist As String) As DataTable
Dim dtclone As DataTable = dt.Clone
Dim dv As New DataView(dt)
dv.Sort = dist
Dim myselold As String = ""
For i As Integer = 0 To dv.Count - 1
If myselold <> dv(i)(dist).ToString Then
Dim drn As DataRow = dtclone.NewRow
For y As Integer = 0 To dv.Count - 1
drn(y) = dv(i)(y)
Next
myselold = dv(i)(dist).ToString
dtclone.Rows.Add(drn)
End If
Next
Return dtclone
End Function
End Class
 
Back
Top