Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

Counting rows in access db...

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?
Avatar of Member_2_5230414
Member_2_5230414

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial