 |
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

February 1st, 2006, 02:24 AM
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Get total records
I'm using command object and I want to be able to display the records found in the SELECT statement in the recordset
so I perform the following: let's say strSQL is my SELECT string
objCommand.CommandText = "SELECT PRICE, NAME .....etc"
Set objRS = objCommand.Execute totalRecordsFound
This gives me an error. how can i get the total records in the recordset once the objCommand is executed??
thx
|

February 1st, 2006, 07:30 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
If you use a cursor type other than forward-only you can use the RecordCount property e.g.
Code:
myRecordCount = objRs.RecordCount
HTH,
Chris
|

February 1st, 2006, 09:53 AM
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how can i specify a cursor type if i'm using command object, not connection?. when i'm using a connection object i would do it like this:
objRS.Open = "SElect ...etc", strConnect, adOpenStatic, adLock....
but with a connection you do this:
Set objRS = objCommand.Execute
so where would i specify the cursor type when using a Command Object?
|

February 1st, 2006, 10:56 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You can open a recordset with the command object as the source parameter e.g.
Code:
Set rs = Server.CreateObject("ADODB.Recordset")
Call rs.Open(cmdObj, , adOpenStatic)
HTH,
Chris
|

February 1st, 2006, 12:59 PM
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yes, but what if i don't want to use connection object, i want to use command object instead. where do i specify the cursor type in this?
set objRS = objCommand.Execute
|

February 1st, 2006, 01:05 PM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
The code I posted above does not pass a connection object to the Open() call, it passes a command object.
It does the equivalent of the command Execute() call but allows you to specify additional parameters, in this case the cursor type.
|

February 1st, 2006, 02:40 PM
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
awesome, thank you. will try tonight.
|

February 1st, 2006, 06:32 PM
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
nope, this still doesn't work. here's my code, maybe this will help
<%
Dim totRec 'total number of records
Dim rsFaq 'recordset
Dim objCommand 'command object
Set objCommand = Server.CreateObject("ADODB.Command") 'create command
'fill command properties
objCommand.ActiveConnection = strConnect
objCommand.CommandText = "INSERT INTO faq(QUESTION, ANSWER) VALUES ('new question10?', 'new answer10')"
objCommand.CommandType = adCmdText
'execute insert command
objCommand.Execute
'execute command
objCommand.CommandText = "SELECT * FROM FAQ"
rsFaq.Open(objCommand, , adOpenStatic)
totRec = rsFaq.RecordCount
'clean up command object
Set objCommand = Nothing
'-----------------------------------------------------------
'display all records
Do While NOT rsFaq.EOF
Response.Write (rsFaq("Question") & "<br>")
Response.Write rsFaq("Answer") & "<br>"
rsFaq.MoveNext
Loop
Response.Write("<BR>" & "Total number of records: " & totRec)
'------------------------------------------------------------
'if no records are found
If rsFaq.BOF Then
Response.Write("No records found in the database")
End if
'close recordset
rsFaq.Close
Set rsFaq = Nothing
%>
|

February 2nd, 2006, 05:05 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You need to create rsFaq as a recordset before you open it and if you're using parentheses on the Open() call, add "Call" before it, so change the line
Code:
rsFaq.Open(objCommand, , adOpenStatic)
to
Code:
Set rsFaq = Server.CreateObject("ADODB.Recordset")
Call rsFaq.Open(objCommand, , adOpenStatic)
|

February 4th, 2006, 09:40 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
simply you can try this
set cn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
cn.ConnectionString="............" // connection string
cn.Open
rs.Open "SELECT * FROM tabename",cn,3,1
rs.PageSize=10000 // optional page length
Response.Write("Total No of Records = "& rs.RecordCount&"<br>")
regards
Mateen
|
|
 |