Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27059

Get Record count

$
0
0
Hi I am trying to get the total count of records in a table, I was looking for something like record count but cannot find anyway thing. How ever I have done tow function to return the record count I was wondering if you guys knew of a different way or witch one of my functions may be the best one to use.


Witch one would you use A or B

Code:

    Public Function RecordCountA() As Integer
        Dim da As OleDbDataAdapter = Nothing
        Dim dt As New DataTable

        Dim Sql As String = "SELECT * FROM SOFTWARE"

        Dim o As New OleDb.OleDbDataAdapter(Sql, dbConn)
        'Fill table
        o.Fill(dt)
        'Return count
        Return dt.Rows.Count
    End Function


    Public Function RecordCountB() As Integer
        Dim da As OleDbDataAdapter = Nothing
        Dim Count As Integer = 0

        Dim Sql As String = "SELECT * FROM SOFTWARE"
        Dim cmd As New OleDbCommand(Sql, dbConn)
        Dim dr As OleDbDataReader = cmd.ExecuteReader

        While dr.Read
            Count += 1
        End While

        Return Count
    End Function

Thanks,

Viewing all articles
Browse latest Browse all 27059

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>