Counting rows in access db...

Posted on 2011-04-28
Medium Priority
Last Modified: 2012-06-27
I currently have this code
  Shared Function noposts(ByVal forumname As String) As Results
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\perkinj\My Documents\Visual Studio 2010\WebSites\runningprofiles\forums\forum.mdb;")
        Dim cmd As New OleDbCommand
        cmd.Connection = con
        cmd.Parameters.AddWithValue("@forumname", forumname)
            cmd.CommandText = "Select Count(*) From forum where Forum =@forumname"
            Dim Res As Results
            Res.Result1 = cmd.ExecuteScalar()
            cmd.CommandText = "Select Count(*) From forum where Forum =@forumname and numrep = 0  "
            Res.Result2 = cmd.ExecuteScalar()

            cmd.CommandText = "Select TOP 1  title + '|' + LastPoster +'|' + Format(lasttime, 'dd/mm/yyyy hh:mm:ss') from forum where Forum =@forumname AND numrep = 0 order by lasttime DESC"
            Res.Result3 = cmd.ExecuteScalar()
            Return (Res)
        Catch ex As Exception
            Throw ex
        End Try
    End Function

Open in new window

i have 3 options i use to get no of threads from different forums
    Dim Res As Results = Class1.noposts("general")
        threads.Text = Res.Result1
 Dim Res As Results = Class1.noposts("races")
        threads.Text = Res.Result1
 Dim Res As Results = Class1.noposts("info")
        threads.Text = Res.Result1

now could i add all 3 together without changing the code above or would i have to re-write the code?
Question by:runnerjp2005

Author Comment

ID: 35483130
this is the way i have done it but seems long winded

  Dim Res As Results = Class1.noposts("Injurys&Health")
        Dim Res2 As Results = Class1.noposts("general")
        Dim Res3 As Results = Class1.noposts("News")
        Dim Res4 As Results = Class1.noposts("General")
        Dim Res5 As Results = Class1.noposts("Training&Races")

        Dim totalthreads As Integer = Res.Result1 + Res2.Result1 + Res3.Result1 + Res4.Result1 + Res5.Result1

        threads.Text = totalthreads

Open in new window

LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 35483517
Try this

        Dim totalthreads As Integer = Class1.noposts("Injurys&Health").Result1 + Class1.noposts("general").Result1 + Class1.noposts("News").Result1 + Class1.noposts("General").Result1 + Class1.noposts("Training&Races").Result1
        threads.Text = totalthreads

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

862 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