Reply
why -1 returned from rs.recordcount
Old 05-27-2005, 04:25 PM why -1 returned from rs.recordcount
numbenator's Avatar
Ultra Talker

Posts: 411
Location: London
HI im using the below connection to select records

conn_string = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Option=16834;Database=col lagenRX;Uid=colladmin;Pwd=collrx;"
oconn.Open(conn_string)
mySQL = "SELECT * FROM products"
Set productRS = oconn.Execute(mySQL)


can anyone tell me why when I output productRS.recordcount , -1 is output.

Cheers for you input
__________________
www.mastech-solutions.com
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
When You Register, These Ads Go Away!
Old 05-27-2005, 05:02 PM
chrishirst's Avatar
Super Moderator

Posts: 13,474
Location: Blackpool. UK
you need to set the cursor location to clientside and use the open method rather than execute
Code:
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorLocation = adUseClient
objRS.Open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText
and you can download the adovbs file from here
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-27-2005, 06:08 PM
numbenator's Avatar
Ultra Talker

Posts: 411
Location: London
Yeah thanks for your input,
I've been messing with your idea and having some difficulties. Hopefully you wont mind taking a glance at. The code i have doesn't error but i m not out putting any records. I thought maybe i should go to movefirst (just in case) but that produced a server error. the code and connection is nelow :

Dim oConn
dim conn_string
Set oConn = Server.CreateObject("ADODB.Connection")
conn_string = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Option=16834;Database=col lagenRX;Uid=colladmin;Pwd=collrx;"
oconn.Open(conn_string)
mySQL = "SELECT * FROM products"

Set productRS = Server.CreateObject("ADODB.Recordset")
productRS.CursorLocation = adUseClient
productRS.Open mySQL, oConn, adOpenStatic, adLockReadOnly, adCmdText
productRS.moveFirst

%>

Ive also included the adovbs file. As said, the productRS.movefirst is causing sever error ... as is at here http://www.collagenrx.co.uk/products.asp

If i take out the moveFirst, the code runs thruogh but no records are located.

Anyway help you can give would be much appreciated.

cheers
__________________
www.mastech-solutions.com
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 05-27-2005, 06:49 PM
chrishirst's Avatar
Super Moderator

Posts: 13,474
Location: Blackpool. UK
You would need to get rid of the custom 500 error page so you can see what is going wrong.

Anyhow, the movefirst will cause an error if there are no records in the recordset. to avoid this use

if not RS.eof or not RS.bof then
' recordset processing here
else
response.write "No records found"
end if
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-28-2005, 05:01 AM
numbenator's Avatar
Ultra Talker

Posts: 411
Location: London
HI there,
cheers for you timne firstly. it is appreciated.
My database does have records in it so i looked further into the code and I have since removed productRS.CursorLocation = adUseClient. When this line is used, no records are located.
ive put the source here http://www.collagenrx.co.uk/products.txtThis consequently has let the page work however i am still stuck with -1


To temporarilly botch it, I have inserted another open recordset and run a loop through that with a count. Not the most efficient ways of doing things i think.
__________________
www.mastech-solutions.com

Last edited by numbenator : 05-28-2005 at 05:45 AM.
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 05-28-2005, 06:04 AM
chrishirst's Avatar
Super Moderator

Posts: 13,474
Location: Blackpool. UK
the most efficient way is to use GetRows() to recover records.

Code:
objRS.open ......
varArray = objRS.getrows()
objRS.close
This returns a 2 dimensional array with all the retrieved records and means you can close and destroy the RS object immediately. If you need the record count it will be
Code:
 ubound(varArray,2) + 1
It also means your code will not be affected by the text field bug in asp.

for error checking I use

Code:
dim varArray
objRS.open ...
if objRS.eof or objRS.bof then
      redim varArray(1,1)
      varArray(0,0) = [a value for an error flag]
      varArray(0,1) = "Not Configured"
else
      varArray = objRS.getrows()
end if
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-28-2005, 06:08 AM
numbenator's Avatar
Ultra Talker

Posts: 411
Location: London
wicked. thanks very much.
__________________
www.mastech-solutions.com
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Reply     « Reply to why -1 returned from rs.recordcount
 

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15439 seconds with 12 queries