?
Solved

Count Values in table

Posted on 2005-03-11
8
Medium Priority
?
161 Views
Last Modified: 2010-04-23
Hi,

Help again!  I may be way off on this but here goes.  I have a Subscribers table in Access with a SubFodId column.  What I am trying to do is display the number of records for each SubFodId and what the SubFodId is.


for example:

DS = 11,034 Subcribers
SW =    456 Subscribers
S4D =   125 Subscribers

etc...

The below returns a value of 5 which I guess is the number of different SubFodId's presently in the column.

Dim dap3 As New OleDb.OleDbDataAdapter( _
                  "SELECT distinct count (Subscribers.SubFodID) FROM(Subscribers)GROUP BY Subscribers.SubFodID;", _
                  "Provider = Microsoft.Jet.OleDb.4.0;" & _
                  "Data Source=c:\Program Files\Nads\NadsDatabase.mdb")

Dim das3 As New System.Data.DataSet

 dap3.Fill(das3, "Subscribers")
        txtFodId.Text = ("FOD " & _
                das3.Tables(0).TableName & " is " & _
                das3.Tables(0).Rows.Count.ToString & ".")
        das2.Clear()

I hope I explained this okay.  If not let me know.  Thanks for your help.
0
Comment
Question by:maralans
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 14

Expert Comment

by:amyhxu
ID: 13521893
Suppose you have a "Subscribers_Name" column for each record:

Dim dap3 As New OleDb.OleDbDataAdapter( _
                  "SELECT count (Subscribers.Subscribers_Name) as Number_Of_Subscribers, SubFodID FROM (Subscribers) GROUP BY Subscribers.SubFodID;", _
                  "Provider = Microsoft.Jet.OleDb.4.0;" & _
                  "Data Source=c:\Program Files\Nads\NadsDatabase.mdb")
0
 
LVL 5

Author Comment

by:maralans
ID: 13521940
That returns the same value.  I don't think I explained this very well.  My subscribers table has 12,000 records of which 5,000 are DS, 3,000 are SW, 2,000 are S4D etc...

What I want to display is:

DS = 5,000 Subcribers
SW = 3,000 Subscribers
S4D = 2,000 Subscribers

etc....

In other words, I want to display the total number of subscribers for each SubFodId and display the SubFodId along with the number.


I hope thats better.
0
 
LVL 14

Expert Comment

by:amyhxu
ID: 13521942
Continued from my last post:

Dim das3 As New System.Data.DataSet

Dim txtFodId As String = ""
For Each dRow as DataRow In das3.Tables("Subscribers")
    txtgFodId = txtFodId & dRow("SubFodID").toString & " = " & dRow("Number_Of_Subscribers").toString & " Subscribers" & vbCrlf
Next

Console.WriteLine(txtFodId)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:amyhxu
ID: 13521950
How about now?

Dim dap3 As New OleDb.OleDbDataAdapter( _
                  "SELECT count (Subscribers.SubFodID) as Number_Of_Subscribers, SubFodID FROM (Subscribers) GROUP BY Subscribers.SubFodID;", _
                  "Provider = Microsoft.Jet.OleDb.4.0;" & _
                  "Data Source=c:\Program Files\Nads\NadsDatabase.mdb")

Dim das3 As New System.Data.DataSet

Dim txtFodId As String = ""
For Each dRow as DataRow In das3.Tables("Subscribers")
    txtgFodId = txtFodId & dRow("SubFodID").toString & " = " & dRow("Number_Of_Subscribers").toString & " Subscribers" & vbCrlf
Next

Console.WriteLine(txtFodId)
0
 
LVL 5

Author Comment

by:maralans
ID: 13522014
I get the following error on  the following line.


Expression is of type "system.data.datatable' which is not a collection type.

For Each dRow As DataRow In das3.Tables("Subscribers")

=====================================================================

This is what I have:

   Dim dap3 As New OleDb.OleDbDataAdapter( _
                  "SELECT count (Subscribers.SubFodID) as Number_Of_Subscribers, SubFodID FROM (Subscribers) GROUP BY Subscribers.SubFodID;", _
                  "Provider = Microsoft.Jet.OleDb.4.0;" & _
                  "Data Source=c:\Program Files\Nads\NadsDatabase.mdb")

        Dim das3 As New System.Data.DataSet

        Dim txtFodId As String = ""
        For Each dRow As DataRow In das3.Tables("Subscribers")
            txtgFodId = txtFodId & dRow("SubFodID").ToString & " = " & dRow("Number_Of_Subscribers").ToString & " Subscribers" & vbCrLf
        Next

        Console.WriteLine(txtFodId)
0
 
LVL 14

Accepted Solution

by:
amyhxu earned 2000 total points
ID: 13522069
For Each dRow As DataRow In das3.Tables("Subscribers").Rows
0
 
LVL 5

Author Comment

by:maralans
ID: 13522092
Okay, we are real close.  Its displaying it correctly in the console but I don't get anything in the textbox.  Any ideas?
0
 
LVL 5

Author Comment

by:maralans
ID: 13522156
Aw, I got it.  Thank you very much for your help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question