There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
ADO Please explain the difference


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
FretBuzzz's Avatar
Junior Member with 9 posts.
 
Join Date: Apr 2007
Experience: Advanced
05-May-2007, 12:43 PM #1
ADO Please explain the difference
Hi, can somebody please explain the difference between the following two blocks of code:
(And when its a good idea to use one or the other)

Block A
========================================
dim myConnection, myRecordSet, myQuery
set myConnection = Server.createObject("adodb.connection")
myConnection.open "MY_DB"
set myRecordSet = server.createobject("adodb.recordset")
myQuery = "select * from myTable where myFieldB='x'"
dbtbl.open myQuery, myConnection , adOpenDynamic , adLockOptimistic
myRecordset("myFieldA") = "myNewvalue"
myRecordset.update
========================================

AND

Block B
========================================
dim myConnection, myRecordSet, myQuery
set myConnection = server.createobject("adodb.connection")
myConnection.open "MY_DB"
myQuery = "update myTable set myFieldA='myNewValue' where myFieldB='x'"
set myRecordSet = myConnection.execute(myQuery)
========================================

Thanks in advance,
FretBuzzz
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
05-May-2007, 03:06 PM #2
Different query so each does a different task.
FretBuzzz's Avatar
Junior Member with 9 posts.
 
Join Date: Apr 2007
Experience: Advanced
05-May-2007, 05:47 PM #3
Show me the light
From where I'm sitting, the results of these procedures are exactly the same... Which is better to use ?
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
06-May-2007, 03:26 AM #4
myQuery = "update myTable set myFieldA='myNewValue' where myFieldB='x'"
myQuery = "select * from myTable where myFieldB='x'"

2 different queries.
FretBuzzz's Avatar
Junior Member with 9 posts.
 
Join Date: Apr 2007
Experience: Advanced
06-May-2007, 01:46 PM #5
Obviously but......
Thank you for that observation. Please note though that my question does not revolve around the queries, but the entire blocks of code. So I'll say again: Both these blocks of code do EXACTLY the same thing... My question is: Which block of code is better to use?
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
06-May-2007, 03:46 PM #6
And I'm saying that they don't both do the same thing.

Edit: Hmm... After closer observation it seems that they do seem to do the same thing although I could be wrong.

Basically they both update myFieldA to myNewValue however they do it using a different method.

However this might do some other config or changes: dbtbl.open myQuery, myConnection , adOpenDynamic , adLockOptimistic.

I would use the latter. What code is this? ASP/VBS?
__________________
Guys, please, this is free tech support, act accordingly.

Last edited by MMJ : 06-May-2007 03:51 PM.
FretBuzzz's Avatar
Junior Member with 9 posts.
 
Join Date: Apr 2007
Experience: Advanced
06-May-2007, 04:02 PM #7
Ok.... then what am I missing ?
As far as I can see, both blocks of code cause myFieldA in myTable to be changed to myNewValue, but only where an X is found in myFieldB

So what's the difference if both snippets produce the same results ?
FretBuzzz's Avatar
Junior Member with 9 posts.
 
Join Date: Apr 2007
Experience: Advanced
06-May-2007, 04:03 PM #8
Yes, it's VBS in ASP
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
08-May-2007, 02:45 AM #9
Quote:
Originally Posted by FretBuzzz
As far as I can see, both blocks of code cause myFieldA in myTable to be changed to myNewValue, but only where an X is found in myFieldB

So what's the difference if both snippets produce the same results ?
Not too sure, never programmed in asp. One seems to be more specific.
harmor's Avatar
Senior Member with 117 posts.
 
Join Date: Mar 2007
Experience: Intermediate
08-May-2007, 04:51 AM #10
Use Block B.

Edit:
What if you did this...
Code:
dim myConnection, myRecordSet, myQuery
set myConnection = server.createobject("adodb.connection")
myConnection.open "MY_DB"
set myRecordSet = myConnection.execute("update myTable set myFieldA='myNewValue' where myFieldB='x'")
cristobal03's Avatar
Distinguished Member with 2,992 posts.
 
Join Date: Aug 2005
Experience: Advanced
09-May-2007, 01:47 PM #11
Block B is faster and probably safer data-wise. To answer your original question, the difference is that the first example pulls a set of data into a recordset that is is created on the fly, then opens the recordset and changes the values of fields using what I assume is a built-in ASP function. The second example uses SQL native to the database itself to do the same thing in a single step.

HTH

chris.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:40 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.