Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > execute sql count statement in asp

Reply
Thread Tools

execute sql count statement in asp

 
 
Matt
Guest
Posts: n/a
 
      01-11-2004
In ASP page, if we want to retrive the number of rows in database: should we
use recordset object? Since this is not update, insert, delete, or select
statement

sqlStmt = "SELECT COUNT(*) from table1;"
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.open sqlStmt, strConnect

But how do we can the value?



 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      01-11-2004

"Matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In ASP page, if we want to retrive the number of rows in database: should

we
> use recordset object? Since this is not update, insert, delete, or select
> statement


Yes, you should, since you need to retrieve a value. But it'd be like so:

sqlStmt = "SELECT COUNT(*) from table1;"
Set oADO = Server.CreateObject("ADODB.Connection")
oADO.Open strConnect
Set rsCount = oADO.Execute(sqlStmt)
iCount = rsCount.Fields.Item(0).Value
rsCount.Close : Set rsCount = Nothing
oADO.Close : Set oADO = Nothing

Response.Write "The count is " & iCount


Just be aware of issues with counting * as opposed to a specific column that
will always have a value, ie. the PK. See here, at least.
http://www.aspfaq.com/show.asp?id=2073

Ray at home


>
> sqlStmt = "SELECT COUNT(*) from table1;"
> Set objRS = Server.CreateObject("ADODB.RecordSet")
> objRS.open sqlStmt, strConnect
>
> But how do we can the value?
>
>
>



 
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
bind invalid when execute oracle sql statement. wqhflp@gmail.com Python 0 08-07-2006 02:47 AM
Which of switch statement and if-else statement takes less time to execute? swaroophr@gmail.com C Programming 21 08-02-2005 09:24 AM
Count(*) in a Subquery with multiple tables: How does SQL determine which table to generate the Count() from? Kaimuri MCSD 3 12-29-2004 06:38 PM
asp and sql statement in sql server db weiwei ASP General 3 09-22-2004 04:12 PM
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM



Advertisments