VB 2012 - Help Finding Specific Numbers in a Database Column and Count the Number of Times They Appear.

Hello,
I am doing a project that uses MS Access to access data about a baseball team . The MS Access Database provides the names, addresses, and age of the players. All the players are 12, 13, or 14 years old. I need to display the average age for the team on a
label, which was easy. The problem is that I also have to display the number of players who are 12, 13, and 14 years old and I have no idea how to do that.
Here is my code so far:
Public Class frmBaseball
Private Sub TeamBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TeamBindingNavigatorSaveItem.Click
Me.Validate()
Me.TeamBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.LittleLeagueDataSet)
End Sub
Private Sub frmBaseball_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LittleLeagueDataSet.Team' table. You can move, or remove it, as needed.
Me.TeamTableAdapter.Fill(Me.LittleLeagueDataSet.Team)
End Sub
Private Sub btnAges_Click(sender As Object, e As EventArgs) Handles btnAges.Click
Dim strSql As String = "SELECT * FROM Team"
Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" & "Data Source=e:\LittleLeague.accdb"
Dim odaTeam As New OleDb.OleDbDataAdapter(strSql, strPath)
Dim datAge As New DataTable
Dim intCount As Integer = 0
Dim intTotalAge As Integer
Dim decAverageAge As Decimal
odaTeam.Fill(datAge)
odaTeam.Dispose()
For intCount = 0 To datAge.Rows.Count - 1
intTotalAge += Convert.ToInt32(datAge.Rows(intCount)("Age"))
decAverageAge = Convert.ToDecimal(intTotalAge / datAge.Rows.Count)
Next
lblAverage.Visible = True
lblAverage.Text = "The average age of the team is " & decAverageAge.ToString("N2")
lbl12.Text = "The number of 12 year olds is "
lbl13.Text = "The number of 13 year olds is "
lbl14.Text = "The number of 14 year olds is "
lbl12.Visible = True
lbl13.Visible = True
lbl14.Visible = True
End Sub
End Class
I think I should use a For..Next loop but I don't know how to identify and match using this database, and then count how many repeated 12, 13, 14 years old there are.
Any help would be really appreciated.

Hello,
Conceptually speaking you would group the data and count. Beings this is school work the demo below is a static example and not suitable for your assignment, its to show a point. Now if you have learned about LINQ and Lambda this logic can apply to your
question but need to work out using this your data which can be done. If not look at using SQL Grouping.
Example of SQL grouping and count
select country, count(country) as count from customers group by country
Module Module1
Public Sub GroupingDemo()
Dim dt As DataTable = SimulateLoadFromDatabase()
Dim TeamData = dt.AsEnumerable.GroupBy(
Function(student) student.Field(Of Integer)("Age")) _
.Select(Function(group) New With
Key .Value = group.Key,
Key .Info = group.OrderByDescending(
Function(x) x.Field(Of String)("Name"))}) _
.OrderBy(
Function(group) group.Info.First.Field(Of Integer)("age"))
Dim dictData As New Dictionary(Of String, String)
For Each group In TeamData
Console.WriteLine("Group: {0} count: {1} ", group.Value, group.Info.Count)
dictData.Add(group.Value.ToString, group.Info.Count.ToString)
' The following is not needed but good to show
For Each item In group.Info
Console.WriteLine(" {0} {1}",
item.Field(Of Integer)("Identifier"),
item.Field(Of String)("Name"))
Next
Next group
Console.WriteLine()
Console.WriteLine("This data can be used to populate control text")
For Each Item As KeyValuePair(Of String, String) In dictData
Console.WriteLine("{0} {1}", Item.Key, Item.Value)
Next
End Sub
Private Function SimulateLoadFromDatabase() As DataTable
Dim dt As New DataTable With {.TableName = "MyTable"}
dt.Columns.Add(New DataColumn With {.ColumnName = "Identifier", .DataType = GetType(Int32),
.AutoIncrement = True, .AutoIncrementSeed = 1})
dt.Columns.Add(New DataColumn With {.ColumnName = "Name", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn With {.ColumnName = "Age", .DataType = GetType(Int32)})
dt.Rows.Add(New Object() {Nothing, "Bill", 13})
dt.Rows.Add(New Object() {Nothing, "Karen", 14})
dt.Rows.Add(New Object() {Nothing, "Jim", 13})
dt.Rows.Add(New Object() {Nothing, "Paul", 15})
dt.Rows.Add(New Object() {Nothing, "Mike", 14})
dt.Rows.Add(New Object() {Nothing, "Jill", 13})
Return dt
End Function
End Module
Output in the IDE output window
Group: 13 count: 3
3 Jim
6 Jill
1 Bill
Group: 14 count: 2
5 Mike
2 Karen
Group: 15 count: 1
4 Paul
This data can be used to populate control text
13 3
14 2
15 1
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

Similar Messages

  • Calling a file and counting the number of words in it-please help!!

    * @(#)WordCounterTwo.java
    * WordCounterTwo application
    * @author
    * @version 1.00 2007/11/17
    import java.util.Scanner;
    public class WordCounterTwo {
    public static void main(String[] args) {
         Scanner keyboard = new Scanner(System.in);
         String fileName;
         int countWords;
         System.out.println("Please enter the name of the file: ");
         fileName = keyboard.nextLine();
         System.out.println(countWords.lastIndexOf());
    }

    I am getting error message as follows:
    cannot find symbol constructor StringTokenizer() on line
    I am asking the user to enter the name of a file, and the output is supposed to display the number of words in the file that chosen. I'm not sure if I am going about this right way, and not sure why I am getting the erorr messages.
    * @(#)WordCounter.java
    * WordCounter application
    * @author
    * @version 1.00 2007/11/17
    import java.util.Scanner;
    import java.util.StringTokenizer;
    public class WordCounter {
        public static void main(String[] args) {
             String sentence;
             Scanner keyboard = new Scanner(System.in);
             StringTokenizer words = new StringTokenizer();  //line 17
             int numberWords;
             System.out.println("Please enter a sentence");
             sentence = keyboard.nextLine();
             sentence = words.nextToken();
             while (words.hasMoreTokens())
                  numberWords++;
             System.out.println(numberWords);
    }

  • HT4640 I have been developing a keynote presentation & want to play audio across several slides. Also want to insert movies made in final cut X but am finding I have to go to black and double click movie files before they appear. looks awful to do that.

    I am new to Keynote and the newest version was just installed in my apps.  I have found difficulty in using audio in a presentation since my presentation plays various audio clips over several slides or movie clips.  My solution has been to create movies with my audio (.mov from final cut x) and insert into the presentation.  They play in the presentation but I cannot get a smooth transition. The presntation must go to black and I have to double click for every "slide" that is done this way.  I am on the verge of going back to powerpoint as my presentation platform. Seems there is little or no flixibility in keynote.

    I am new to Keynote and the newest version was just installed in my apps.  I have found difficulty in using audio in a presentation since my presentation plays various audio clips over several slides or movie clips.  My solution has been to create movies with my audio (.mov from final cut x) and insert into the presentation.  They play in the presentation but I cannot get a smooth transition. The presntation must go to black and I have to double click for every "slide" that is done this way.  I am on the verge of going back to powerpoint as my presentation platform. Seems there is little or no flixibility in keynote.

  • Find one character in a string and count the amount of times its found

    Hey SQL Forum experts.
    I have a string that is about 3000 characters long.
    I'm trying to search my string for the value '{'.
    Then I want to count how many times this value is found.
    How do I form the Oracle SQL to do this?

    Hi Colin,
    Try the following:
    SQL> var s varchar2(100)
    SQL>
    SQL> exec :s := 'Colin {{ Mackenzie {{{'
    PL/SQL procedure successfully completed.
    SQL> select length(:s) - length(replace(:s, '{')) Matches from dual;
       MATCHES
             5
    SQL> exec :s := 'I have a string that is about 3000 characters long'
    PL/SQL procedure successfully completed.
    SQL> select length(:s) - length(replace(:s, '{')) Matches from dual;
       MATCHES
             0Regards.

  • HT201272 I have numbers and pages on my iPhone but cannot seem to transfer them to the mac I purchased today ? Are they formatted for the iPhone only ? They appear to be downloaded but I cannot find them on the MAC - where should I look ?

    I have numbers and pages on my iPhone but cannot seem to transfer them to the mac I purchased today ? Are they formatted for the iPhone only ? They appear to be downloaded but I cannot find them on the MAC - where should I look ?

    Welcome to the Apple community.
    The apps you have purchased for your mobile device will not work on a computer. You will need to download the appropriate versions on your Mac from the Mac apps store.

  • I want to remove the monitor from my 17" Macbook Pro 2008 to use as an external for my Macbook Pro 15" 2012. How can I convert lvds to Thunderbolt and power the monitor?

    I want to remove the monitor from my 17" Macbook Pro 2008 to use as an external for my Macbook Pro 15" 2012. How can I convert lvds to Thunderbolt and power the monitor?

    It's almost impossible.  The new iMacs have a Target Display Mode, but it's built to do that.  Without ripping your screen out, finding an acceptable power supply, frame, and whatever electronics to convert a Thunderbolt signal to the screen, the cost will be much larger than buying a cheaper HiDef monitor that runs with an HDMI to Thunderbolt cable to your MacBook 15.  In fact, you can sell your 17" MBP for a lot of money, unless it's broken or something, buying you a really sweet monitor.
    By the way, I found your answer by searching this forum.  I would suggest using the search function here in the futuere.

  • When I play games in Mozilla on fb..some setting changed and now the pop up window that appears to send gifts to my friends only lists 3 ppl at a time some games i have a scroll down button others i dont..can u help m fix this please?

    When I play games in Mozilla on fb..some setting changed and now the pop up window that appears to send gifts to my friends only lists 3 ppl at a time some games i have a scroll down button others i dont..can u help m fix this please?

    Hi Winnie
    Unfortunately I have been sick and did not read the message before. I apologize.
    I have not received help beyond what is on the page. But when I get I tell you.
    I hope you can get answers. If you receive, I ask that you share with me.
    thank you very much
    best regards
    AC
    Date: Mon, 27 Feb 2012 09:33:10 -0700
    From: [email protected]
    To: [email protected]
    Subject: Pop up Window before saving remembering the need (forcing) to fill required fields in a form
        Re: Pop up Window before saving remembering the need (forcing) to fill required fields in a form
        created by Win_Form in Forms - View the full discussion
    Hi ACI wonder if you can share any responses on to your question above?I too have never used a script but, I have the same problems as you in regards to building a form. And wants to have the same 'protection' and message reminders for the end users. Any information, including a script and/or a contact email of experts you can share with me will help tremendously. Thank you so much in advance. Winnie
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4232307#4232307
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4232307#4232307. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Forms by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • How to find the number of times method being called.....

    hi,
    can any one pls tell me how to find the number of times the method being called......herez the example....
    Refrence ref = new Refrence();
    for(int i = 0;i < arr.length; i++){
    if(somecondition){
    ref.getMethod();
    here i want to know how many times the getMethod() is calling...Is there any method to do this.. i have seen StrackTraceElement class..but not sure about that....pls tell me the solution....

    can any one pls tell me how to find the number of times the method being called......
    herez the example.... http://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal ? in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • Generate numbers in incremental order, the number of times condition met?

    I have tried explaining my problem here also.
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=31&t=007531&p=1
    But trying to put in other words now.
    I have a NO tag which appears many times in xml. and alwyas have some random numbers displaying.
    output looks something similar to this
    something......<NO>1</NO>
    something......<NO>1</NO>
    something......<NO>2</NO>
    something......<NO>1</NO>
    something......<NO>3</NO>
    something......<NO>1</NO>
    something......<NO>5</NO>
    something......<NO>1</NO>
    something......<NO>1</NO>
    something...... & so on.
    Now instead of these numbers coming in this order i prefer to display in final output file as
    1 2 3 4 5 .................... n
    Is it possible in any ways using xslt.
    DO we need to ignore the values given in input file and then generate output values for same.
    it can be like the number of times NO tag appears in xml, it should start from 1 and keep increasing value by 1, until NO tag finishes appearance.
    But next time when other xml transforms it again should be able to start from 1 till n.
    is there a possibility of using java code for this situation or xslt is capaable enough to handle this.
    Thanks
    VJ

    I'm guessing you are looking for something like this. I used a pull approach but it could be done with a push (xsl:for-each).
    Sample XML
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
         <NO>1</NO>
         <NO>1</NO>
         <NO>2</NO>
         <NO>1</NO>
         <NO>3</NO>
         <NO>1</NO>
         <NO>5</NO>
         <NO>1</NO>
         <NO>1</NO>
    </root>
    Sample XSLT
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
         <xsl:template match="root">
              <output>
                   <xsl:apply-templates select="NO"/>
              </output>
         </xsl:template>
         <xsl:template match="NO">
              <row>
                   <xsl:value-of select="position()"/>
              </row>
         </xsl:template>
    </xsl:stylesheet>
    Sample Output
    <output>
         <row>1</row>
         <row>2</row>
         <row>3</row>
         <row>4</row>
         <row>5</row>
         <row>6</row>
         <row>7</row>
         <row>8</row>
         <row>9</row>
    </output>

  • Since I installed ios 6.1 in my iPhone 4, I can't sync it with iTunes. Can annyone help me? I have already reinstalled iTunes and reseted the iPhone, but it still doesn't sync. Thank you.

    Since I installed ios 6.1 in my iPhone 4, I can't sync it with iTunes. Can annyone help me? I have already reinstalled iTunes and reseted the iPhone, but it still doesn't sync. Thank you.

    Hello Sean,
    It sounds like you are constantly needing to restore your phone because it keeps going into recovery mode. Usually putting a device into recovery mode and restoring it can help isolate an issue to your iPhone hardware if an issue persists afterwards. I would try manually putting it into recovery mode and restoring it 1 more time:
    If you can't update or restore your iOS device
    http://support.apple.com/kb/HT1808
    If that does not resolve it the symptoms indicate to me that it is a hardware issue causing this to happen and would seek service for it:
    iPhone Repair - Other Repairs
    https://www.apple.com/support/iphone/repair/other/
    Thank you for using Apple Support Communities.
    All the best,
    Sterling

  • Since installing Yosemite and Photos I can now no longer drag and drop a photo in an email, as I have always done. I repaired permission and restarted a number of times. still not working... Help?! Thanks, Michael

    Since installing Yosemite and Photos I can now no longer drag and drop a photo in an email, as I have always done. I repaired permission and restarted a number of times. still not working... Help?! Thanks, Michael

    What happens if you use the Share button and select Mail?
    What happens when you try? I had to hold there photo there for a short period before it would load.

  • In Numbers, I copied a worksheet and deleted the contents. The sheet I copied from has a header, I can't see it or bring it up when I'm working but it appears when I print the sheet. How do I delete it?

    In Numbers, I copied a worksheet and deleted the contents. The sheet I copied has a header.  I can't see it or bring it up when I'm working but it appears when I print the sheet. How do I delete the header?

    Hi Cristina,
    Headers are not shown in normal view.
    Menu > File > Print to open Print View.
    Hover the cursor over the Header to see the outline. Click and delete.
    Regards,
    Ian.

  • Contacts Sync - I have my contacts on iphone5 and MacBook Pro 2012.  I just purchased a MacBook Air 2013 and want the same contacts on that device.  What is the best way to do this?  Non-techie.  Thanks

    I have my contacts on iphone5 and MacBook Pro 2012.  I just purchased a MacBook Air 2013 and want the same contacts on that device.  What is the best way to do this?  Non-techie.  Thanks

    Follow the instructions for enabling your iCloud account on the MBAir here >  Apple - iCloud - Learn how to set up iCloud on all your devices.

  • My iPhone has suddenly started sending emails in Courier New (rather than the standard Arial).  They appear in Arial when I compose them, but turn to Courier new in the sent folder and when displayed to the recipient.  I use Yahoo Mobile Mail.  Help!

    My iPhone has suddenly started sending emails in Courier New (rather than the standard Arial).  They appear in Arial when I compose them, but turn to Courier new in the sent folder and when displayed to the recipient.  I use Yahoo Mobile Mail.  Help!  How can I change the settings so that the sent emails go back to Arial?  Thank you!

    I'm not sure if it's a Yahoo Mobile mail or an iphone issue... have asked the Yahoo forum but no replies yet...  Any help appreciated!

  • Help!! count the number of words in one line

    the question is that use JOptionPane and Array to count the number of words and characters that user inputed.
    for example, if I enter the " this is a java program"
    that messages have display 5 and 18.
    please show me the a completely program.
    thx!!!!

    You guys are heartless. Even you weren't born with programming knowledge hard-coded into your brain. Even you had to start from zero. Even you had to struggle at something in your life. In this spirit, I think that we should give this poor student a break and try to help him as much as possible. Here, try out my program, and perhaps it will give you some ideas for your own:
    public class WordCountingHomework
      public static void main(String[] args) throws InterruptedException
        String input = JOptionPane.showInputDialog("Please enter a String");
        // get your String and split the String into words
        // This will allow you to count words easily
        String[] strArray = new String(wordCountByteArray).split(" ");
        int delay = 400;
        for (;;)
          // loop through the array to count the words
          for (String string : strArray)
            System.out.print(string + " ");
            Thread.sleep(delay);
          System.out.println();
          delay *= 7;
          delay /= 10;
      private static byte[] wordCountByteArray =
        0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x64, 0x6f, 0x20, 0x79, 0x6f,
        0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x61, 0x72, 0x6b, 0x69,
        0x6e, 0x27, 0x20, 0x68, 0x6f, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x21
    }

Maybe you are looking for