Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



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

Posts: 516
Location: London
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 05-27-2005, 06:02 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-27-2005, 07:08 PM
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 05-27-2005, 07:49 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-28-2005, 06:01 AM
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE

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

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-28-2005, 07:08 AM
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
wicked. thanks very much.
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Reply     « Reply to why -1 returned from rs.recordcount
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 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.36536 seconds with 12 queries