Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > getting rowcount

Reply
Thread Tools

getting rowcount

 
 
segue
Guest
Posts: n/a
 
      01-23-2008

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()


 
Reply With Quote
 
 
 
 
Kelly Herald
Guest
Posts: n/a
 
      01-23-2008
Change the ExecuteNonQuery to ExecuteScalar and casting it to an Int32.


"segue" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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()
>
>



 
Reply With Quote
 
 
 
 
segue
Guest
Posts: n/a
 
      01-23-2008

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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > 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()
> >
> >

>
>
>

 
Reply With Quote
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      01-23-2008
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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >
> > > 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()
> > >
> > >

> >
> >
> >

 
Reply With Quote
 
segue
Guest
Posts: n/a
 
      01-23-2008
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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > >
> > > > 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()
> > > >
> > > >
> > >
> > >
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting rowcount from within a repeater control Darrel ASP .Net 2 12-29-2008 04:50 AM
SqlDataReader - ReturnValue - rowcount Jon Haakon Ariansen ASP .Net 3 11-08-2006 04:35 PM
ODS + TableAdapter + Rowcount robert madrian ASP .Net 0 12-19-2005 05:45 PM
DB API specification of .rowcount and/or execute andychambers2002@yahoo.co.uk Python 1 11-14-2005 03:41 PM
rowcount et ASP .Net Datagrid Control 3 09-23-2005 03:59 AM



Advertisments