PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2015 Getting sum of database-VBForums
Results 1 to 3 of 3

Thread: Getting sum of database

  1. #1

    Thread Starter
    New Member tryingtoohard's Avatar
    Join Date
    Dec 2017

    Getting sum of database

    I am trying to write a program that will be able to sum up a total from a database file and am stuck. I've tried a few different ideas and nothing has worked so far. This is what I currently have

    Dim SumQuery = From popualtion In PopulationDBDataSet.City
                           Aggregate population In PopulationDBDataSet.City
                               Into Sum(population)
    I keep getting the error "method sum is not accessible in this context". Has anyone else had this happen to them or have any suggestions?

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011

    Re: Getting sum of database

    I am assuming you want to sum the populations of all cities. I don't know how your classes are defined out so I mocked up an example of a similar problem. Maybe you can use it to help you:-
    vbnet Code:
    1. '
    2. Public Class Form1
    4.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    6.         Dim cities As New List(Of City)
    8.         cities.Add(New City("New York", 9092))
    9.         cities.Add(New City("POS", 3443))
    10.         cities.Add(New City("Kio", 9011))
    11.         cities.Add(New City("Loinitte", 4033))
    13.         'Sum the populations of all cities
    14.         Dim sumOfPop As Integer = Aggregate city In cities Into Sum(city.Population)
    18.     End Sub
    19. End Class
    22. Public Class City
    24.     Public Sub New(ByVal cityName As String, ByVal pop As Integer)
    25.         Me.CityName = cityName
    26.         Me.Population = pop
    27.     End Sub
    29.     Public Sub New()
    31.     End Sub
    33.     Public Property CityName As String
    34.     Public Property Population As Integer
    36. End Class
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: Getting sum of database

    I'm not seeing a reason that it wouldn't just be like this: Code:
    1. Dim SumQuery = PopulationDBDataSet.City.AsEnumerable().Sum(Function(c) c.Population)
    If this is a typed DataSet - which it appears to be - then I don't think that the AsEnumerable is required.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width