Aggregate Data Functions in Disconnected DataSet

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

Guest

H
Is there an easy way of performing the "SELECT Count(columnname), columnname from tablename" database command on a disconnected DataSet to enable me to display a chart of numbers of distinct values, which will vary, in a Windows form

Many thank
djm
 
Hi djm.

Only one answer, No, you have to do a Select distinct of the database for
that.

Or make an itterating routine, not that difficult of course.
I made once a generic sample of it, but I do not know if it real fits your
problem?

You have to test it yourself, I am not sure if I did that completly.

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
///
 
djm,
If all the data you want is in tablename in your DataSet, you can use
DataTable.Compute to find the count.

Dim ds As DataSet
Dim table As DataTable = ds.Tables("tablename")
Dim count As Integer
count = CInt(table.Compute("Count(columnname)", Nothing))

For allowed aggregate functions see the DataColumn.Expression property in
the online help.

Note you will need to use seperate DataTable.Compute calls for each column
you want a count of, alternatively you could "roll your own" loop as Cor
showed and compute all columns in one iteration.

Hope this helps
Jay

djm said:
Hi
Is there an easy way of performing the "SELECT Count(columnname),
columnname from tablename" database command on a disconnected DataSet to
enable me to display a chart of numbers of distinct values, which will vary,
in a Windows form?
 
Back
Top