getting rowcount

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?c2VndWU=?=

    #1

    getting rowcount


    The below code doesn't give me the last record count.
    Feedback very appreciated. Thanks for all that you do.

    qstring = "SELECT COUNT(*) FROM CustomerInforma tion "

    Dim newSql As New SqlConnection(c onnectionstr)
    newSql.Open()
    Dim catCMD As SqlCommand = newSql.CreateCo mmand()
    catCMD.CommandT ext = qstring
    Dim intRecordsAffec ted = catCMD.ExecuteN onQuery()
    newSql.Close()


  • Kelly Herald

    #2
    Re: getting rowcount

    Change the ExecuteNonQuery to ExecuteScalar and casting it to an Int32.


    "segue" <segue@discussi ons.microsoft.c omwrote in message
    news:1DFAB87C-9A9E-476E-959B-D1819968D235@mi crosoft.com...
    >
    The below code doesn't give me the last record count.
    Feedback very appreciated. Thanks for all that you do.
    >
    qstring = "SELECT COUNT(*) FROM CustomerInforma tion "
    >
    Dim newSql As New SqlConnection(c onnectionstr)
    newSql.Open()
    Dim catCMD As SqlCommand = newSql.CreateCo mmand()
    catCMD.CommandT ext = qstring
    Dim intRecordsAffec ted = catCMD.ExecuteN onQuery()
    newSql.Close()
    >
    >

    Comment

    • =?Utf-8?B?c2VndWU=?=

      #3
      Re: getting rowcount


      Thanks for the quick response.

      I made the ExecuteScalar change and still didn't get the highest number.
      My query stopped at 114,278, row 114,279 is empty yet 114,300 isn't.



      "Kelly Herald" wrote:
      Change the ExecuteNonQuery to ExecuteScalar and casting it to an Int32.
      >
      >
      "segue" <segue@discussi ons.microsoft.c omwrote in message
      news:1DFAB87C-9A9E-476E-959B-D1819968D235@mi crosoft.com...

      The below code doesn't give me the last record count.
      Feedback very appreciated. Thanks for all that you do.

      qstring = "SELECT COUNT(*) FROM CustomerInforma tion "

      Dim newSql As New SqlConnection(c onnectionstr)
      newSql.Open()
      Dim catCMD As SqlCommand = newSql.CreateCo mmand()
      catCMD.CommandT ext = qstring
      Dim intRecordsAffec ted = catCMD.ExecuteN onQuery()
      newSql.Close()
      >
      >
      >

      Comment

      • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

        #4
        Re: getting rowcount

        There is a big difference between count(*) which returns a count of the
        number of rows in the table, and MAX(ID) which returns the highest value
        present in the ID column.
        -- Peter
        Site: http://www.eggheadcafe.com
        UnBlog: http://petesbloggerama.blogspot.com
        MetaFinder: http://www.blogmetafinder.com


        "segue" wrote:
        >
        Thanks for the quick response.
        >
        I made the ExecuteScalar change and still didn't get the highest number.
        My query stopped at 114,278, row 114,279 is empty yet 114,300 isn't.
        >
        >
        >
        "Kelly Herald" wrote:
        >
        Change the ExecuteNonQuery to ExecuteScalar and casting it to an Int32.


        "segue" <segue@discussi ons.microsoft.c omwrote in message
        news:1DFAB87C-9A9E-476E-959B-D1819968D235@mi crosoft.com...
        >
        The below code doesn't give me the last record count.
        Feedback very appreciated. Thanks for all that you do.
        >
        qstring = "SELECT COUNT(*) FROM CustomerInforma tion "
        >
        Dim newSql As New SqlConnection(c onnectionstr)
        newSql.Open()
        Dim catCMD As SqlCommand = newSql.CreateCo mmand()
        catCMD.CommandT ext = qstring
        Dim intRecordsAffec ted = catCMD.ExecuteN onQuery()
        newSql.Close()
        >
        >

        Comment

        Working...