getting rowcount
am 23.01.2008 20:26:03 von segue
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()
Re: getting rowcount
am 23.01.2008 20:35:17 von Kelly Herald
Change the ExecuteNonQuery to ExecuteScalar and casting it to an Int32.
"segue" wrote in message
news:1DFAB87C-9A9E-476E-959B-D1819968D235@microsoft.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 CustomerInformation "
>
> Dim newSql As New SqlConnection(connectionstr)
> newSql.Open()
> Dim catCMD As SqlCommand = newSql.CreateCommand()
> catCMD.CommandText = qstring
> Dim intRecordsAffected = catCMD.ExecuteNonQuery()
> newSql.Close()
>
>
Re: getting rowcount
am 23.01.2008 21:33:02 von segue
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:1DFAB87C-9A9E-476E-959B-D1819968D235@microsoft.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 CustomerInformation "
> >
> > Dim newSql As New SqlConnection(connectionstr)
> > newSql.Open()
> > Dim catCMD As SqlCommand = newSql.CreateCommand()
> > catCMD.CommandText = qstring
> > Dim intRecordsAffected = catCMD.ExecuteNonQuery()
> > newSql.Close()
> >
> >
>
>
>
Re: getting rowcount
am 23.01.2008 21:56:02 von pbromberg
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:1DFAB87C-9A9E-476E-959B-D1819968D235@microsoft.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 CustomerInformation "
> > >
> > > Dim newSql As New SqlConnection(connectionstr)
> > > newSql.Open()
> > > Dim catCMD As SqlCommand = newSql.CreateCommand()
> > > catCMD.CommandText = qstring
> > > Dim intRecordsAffected = catCMD.ExecuteNonQuery()
> > > newSql.Close()
> > >
> > >
> >
> >
> >
Re: getting rowcount
am 23.01.2008 22:42:00 von segue
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:1DFAB87C-9A9E-476E-959B-D1819968D235@microsoft.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 CustomerInformation "
> > > >
> > > > Dim newSql As New SqlConnection(connectionstr)
> > > > newSql.Open()
> > > > Dim catCMD As SqlCommand = newSql.CreateCommand()
> > > > catCMD.CommandText = qstring
> > > > Dim intRecordsAffected = catCMD.ExecuteNonQuery()
> > > > newSql.Close()
> > > >
> > > >
> > >
> > >
> > >