We help IT Professionals succeed at work.

Counting rows in access db...

Member_2_5230414
on
339 Views
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)
        Try
            con.Open()
            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
        Finally
            con.Close()
        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?
Comment
Watch Question

Author

Commented:
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

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.