getting rowcount

Discussion in 'ASP .Net' started by segue, Jan 23, 2008.

  1. segue

    segue Guest

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

    qstring = "SELECT COUNT(*) FROM CustomerInformation "

    Dim newSql As New SqlConnection(connectionstr)
    newSql.Open()
    Dim catCMD As SqlCommand = newSql.CreateCommand()
    catCMD.CommandText = qstring
    Dim intRecordsAffected = catCMD.ExecuteNonQuery()
    newSql.Close()
     
    segue, Jan 23, 2008
    #1
    1. Advertising

  2. segue

    Kelly Herald Guest

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


    "segue" <> wrote in message
    news:...
    >
    > The below code doesn't give me the last record count.
    > Feedback very appreciated. Thanks for all that you do.
    >
    > qstring = "SELECT COUNT(*) FROM CustomerInformation "
    >
    > Dim newSql As New SqlConnection(connectionstr)
    > newSql.Open()
    > Dim catCMD As SqlCommand = newSql.CreateCommand()
    > catCMD.CommandText = qstring
    > Dim intRecordsAffected = catCMD.ExecuteNonQuery()
    > newSql.Close()
    >
    >
     
    Kelly Herald, Jan 23, 2008
    #2
    1. Advertising

  3. segue

    segue Guest

    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" <> wrote in message
    > news:...
    > >
    > > The below code doesn't give me the last record count.
    > > Feedback very appreciated. Thanks for all that you do.
    > >
    > > qstring = "SELECT COUNT(*) FROM CustomerInformation "
    > >
    > > Dim newSql As New SqlConnection(connectionstr)
    > > newSql.Open()
    > > Dim catCMD As SqlCommand = newSql.CreateCommand()
    > > catCMD.CommandText = qstring
    > > Dim intRecordsAffected = catCMD.ExecuteNonQuery()
    > > newSql.Close()
    > >
    > >

    >
    >
    >
     
    segue, Jan 23, 2008
    #3
  4. 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" <> wrote in message
    > > news:...
    > > >
    > > > The below code doesn't give me the last record count.
    > > > Feedback very appreciated. Thanks for all that you do.
    > > >
    > > > qstring = "SELECT COUNT(*) FROM CustomerInformation "
    > > >
    > > > Dim newSql As New SqlConnection(connectionstr)
    > > > newSql.Open()
    > > > Dim catCMD As SqlCommand = newSql.CreateCommand()
    > > > catCMD.CommandText = qstring
    > > > Dim intRecordsAffected = catCMD.ExecuteNonQuery()
    > > > newSql.Close()
    > > >
    > > >

    > >
    > >
    > >
     
    Peter Bromberg [C# MVP], Jan 23, 2008
    #4
  5. segue

    segue Guest

    Thanks again for the response. I tried below and get the intRecords = 100,000.

    qstring = "SELECT MAX(CustomerID) FROM CustomerInformation "
    ' ORDER BY RowNumber"

    Dim newSql As New SqlConnection(connectionstr)
    newSql.Open()
    Dim catCMD As SqlCommand = newSql.CreateCommand()
    catCMD.CommandText = qstring
    Dim intRecordsAffected As Int32 =
    CType(catCMD.ExecuteScalar(), Int32)
    intRecordsAffected = intRecordsAffected + 1
    newSql.Close()


    "Peter Bromberg [C# MVP]" wrote:

    > 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" <> wrote in message
    > > > news:...
    > > > >
    > > > > The below code doesn't give me the last record count.
    > > > > Feedback very appreciated. Thanks for all that you do.
    > > > >
    > > > > qstring = "SELECT COUNT(*) FROM CustomerInformation "
    > > > >
    > > > > Dim newSql As New SqlConnection(connectionstr)
    > > > > newSql.Open()
    > > > > Dim catCMD As SqlCommand = newSql.CreateCommand()
    > > > > catCMD.CommandText = qstring
    > > > > Dim intRecordsAffected = catCMD.ExecuteNonQuery()
    > > > > newSql.Close()
    > > > >
    > > > >
    > > >
    > > >
    > > >
     
    segue, Jan 23, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. robert madrian

    ODS + TableAdapter + Rowcount

    robert madrian, Dec 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    401
    robert madrian
    Dec 19, 2005
  2. Replies:
    1
    Views:
    300
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Nov 14, 2005
  3. Jon Haakon Ariansen

    SqlDataReader - ReturnValue - rowcount

    Jon Haakon Ariansen, Nov 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,957
    bruce barker \(sqlwork.com\)
    Nov 8, 2006
  4. Darrel
    Replies:
    2
    Views:
    2,478
    Darrel
    Dec 29, 2008
  5. et

    rowcount

    et, Sep 22, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    162
    Scott Mitchell [MVP]
    Sep 23, 2005
Loading...

Share This Page