help with ado recordset

They have: 46 posts

Joined: Dec 2000

I have need to update a recordset, not a database, and I keep getting an error msg saying I can't. Here is what I am trying to do:

fResults("dnane")=temp

I just want to change the value in a recordset, that is all. I have tried putting this after it:
fResults.Update

But that does nothing at all. How do I do it?

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

is your connection correct/open?

more code would help....

They have: 46 posts

Joined: Dec 2000

Yes, sorry I was at my gf's house and was short on time.

Here is the code I want to get working:

-----------------------------------------
'REMOVE SPACES FROM NAMES SO HTML QUERY CAN BE PASSED
temp=""
temp2=""
temp3=""

do while not fResults.eof
count2=1
count=len(fresults("dname"))

do while count2 <= count
if mid(fResults("dname"), count2, 1) = " " then

temp= left(fResults("dname"), (count2 - 1))
temp2= right(fResults("dname"), (count - count2))
temp3= temp & "%20" & temp2
fResults.fields("dname") = temp3
fResults.Update
-----------------------------------------

That is the stage the code is at now. I have a recordset (fResults) that I pulled form my database. It has names in it that have spaces in them. In need to get rid of these spaces. I know how to do that, I just can't get the fixed name into the recordset. I thought it would be easy, just fResults("dname")=fixeddrivername.

I have not closed anything in the code above it. Just created that recordset.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

what is that code doing?
I see two DO WHILE loops without the LOOP statement.

Also, to remove spaces, use this:
MY_Var = Replace(" ","",MY_Var)

This is what I found in two of my books:

recordset("field") = value
recordset.Update
'
where do you create your connection? is that part working?
where do you populate your recordset?

plz, more code...

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 46 posts

Joined: Dec 2000

The full source for the site can be found here:
http://home.iprimus.com.au/nbrown/cdr.txt

But be warned that it is both massive and quite sloppy. This is my first asp project and I am much more concerned wiht getting it working than I am with optimizing it. Though I do plan to re-code the whole thing once I get it finished and established.

All my other code works fine. That recordset works fine in above code.

Here is where that recordset is created:
--------------------------
SQL="SELECT dname,points,r1,r2,r3,r4 FROM Rankings ORDER BY points desc"

set fResults=dbopen.execute(SQL)
---------------------------

About the missing 'loop', I must not have copied down far enough before I pasted Wink The loops do work.

Here is the completed code:

---------------------------

'REMOVE SPACES FORM NAMES SO HTML QUERY CAN BE PASSED
temp=""
temp2=""
temp3=""

do while not fResults.eof
count2=1
count=len(fresults("dname"))

do while count2 <= count
if mid(fResults("dname"), count2, 1) = " " then

temp= left(fResults("dname"), (count2 - 1))
temp2= right(fResults("dname"), (count - count2))
temp3= temp & "%20" & temp2
fResults("dname") = temp3 'tried fResults.Fields("dname") as well
fResults.Update

end if
count2 = count2 + 1
loop

fResults.movenext
loop
---------------------------

That MY_Var = Replace(" ","",MY_Var) is very interesting. I have never hard of 'replace' before. Though my experence with VB is quite limited.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Replace function: http://msdn.microsoft.com/scripting/vbscript/doc/vsfctReplace.htm

Quote: This is my first asp project...

Your ambitious! (that's good...)

Your loops make more sense now, but try sumthin' more like this:

'REMOVE SPACES FORM NAMES SO HTML QUERY CAN BE PASSED
do while not fResults.eof
  fResults("dname") = Replace(" ","",fResults("dname"))
  fResults.Update
  fResults.movenext
loop
'
or
'REMOVE SPACES FORM NAMES SO HTML QUERY CAN BE PASSED
do while not fResults.eof
  SQL = "UPDATE Rankings SET dname='" & Replace(" ","",fResults("dname")) & "' WHERE dname='" & fResults("dname") & "'"
  dbopen.execute(SQL)
loop
'

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 46 posts

Joined: Dec 2000

Thank you.

I'll try both of those.

They have: 46 posts

Joined: Dec 2000

Thank you very much for your help so far Smiling I have not had any time to toy with this of late.

Whenever I try to use either:

fResults("dname")= "whatever"
or
fResutls.update

I get this error:

ADODB.Recordset error '800a0cb3'

The operation requested by the application is not supported by the provider.

Does this just mean that under PWS and whatever my host is using, I can't use any form of update? Or is there really something wrong with my code?

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

are you using Access?

I searched MSDN, and found this regarding the error:
"The Microsoft Access ODBC Driver does not support multiple result sets of native Access tables."

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 46 posts

Joined: Dec 2000

Oh, and the sql method times out.

They have: 46 posts

Joined: Dec 2000

I am using access.

But what does "multiple result sets of native Access tables" mean?

I have to lean to use MSDN Wink

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I don't know.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

are you making any other queries to that tables later or before in that script?

They have: 46 posts

Joined: Dec 2000

I looked it up and it means that you can't use nextRecordset when using access.

I did not think that it mattered what database I was using once the data was pulled out of it into recordsets...?

Anyway, I don't think I can solve this using ado. I can work around it using a sub program. I'll do that. A little more sloppy, but will get the job done.

Thanks you all your help Smiling

Edit:

I made a new page with just this:

<?php
option explicit
dim dbopen
dim SQL
dim rs


   
'DB CONNECTION
set dbopen=Server.CreateObject("ADODB.Connection")
dbopen.Provider="Microsoft.Jet.OLEDB.4.0"
dbopen.open Server.MapPath("/SHINNATHAN/database/CDR.mdb")


    '
SETUP RECORDSET
SQL
="SELECT dName FROM Drivers"
set rs=dbopen.execute(SQL)
?>

Testing recordset update

<?php
response
.write rs("dname") & "<p>"
rs("dname")= "this"
rs.Update

rs
.close
dbopen
.close
set dbopen
=Nothing
set rs
=Nothing
?>

And still I got the error... I am giving up Wink

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

That's why we're here. Please, feel free to share all your web related problems with us... LOL! Wink

They have: 46 posts

Joined: Dec 2000

One more question Wink

Can you execute sql on a recordset? Would be so great if you could...

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

ummm...
To my knowledge, no.

But what exactly do you mean?

They have: 46 posts

Joined: Dec 2000

Well this here:

do while not rs.eof
SQL2 = "UPDATE Rankings SET dname='" & Replace(rs("dname")," ","%20") & "' WHERE dname='" & rs("dname") & "'"
dbopen.execute(SQL2)
rs.movenext
loop

If instead of updating the 'dname' feild in the 'Rankings' table, I could be updating the 'dname' feild in the rs recordset. That way I would not have to create another recordset just to get the data back form that table.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

ahhh...
No, I've never seen/heard anything like that.

They have: 19 posts

Joined: Feb 2001

No, a recordset is just a container for result rows - to execute SQL on it, it has to be connected to an ADO provider. For the original problem you asked about, look into the options you can set for the CursorType.

StoreScanner.com - Local & online comparison shopping: audio, video, photo, appliances & more. Compare features, find rebates and coupons, link to manufacturers, find local & online stores.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Got into this one kind of late.

You can update multiple recordsets at once when using ADO. Make sure the cursortype is "adOpenKeyset" and the locktype is "adLockBatchOptimistic". Then you can use the UpdateBatch method.

PJ | Are we there yet?
pjboettcher.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.