Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 27th, 2008, 11:23 AM
bryceowen bryceowen is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 49 bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 2 h 10 m 37 sec
Reputation Power: 6
Looking for a little clarification on ADO...

I was wondering if anyone could clarify a couple things about ADO for me. I've been looking at the tutorials on w3schools and, while they are very thorough, I'm still a little confused.

For example, this snippet from w3schools shows how to connect to an access database:
Code:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>


This code, however, is what I'm currently using. I found it in another tutorial and liked it because of the server.mappath line:
Code:
<%
Set Conn = Server.CreateObject("ADODB.Connection")
  sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=" & Server.MapPath("../master.mdb") & ";" & _
  "Persist Security Info=True"
Conn.Open(sConnection)
%>


In the w3schools code, they have a conn.provider line and a conn.open line whereas in the code I'm using, the provider and database are in one variable then opened together.

Is one more efficient than the other? How would I use the server.mappath command in the w3school example?

This next question has more to do with HOW a command functions.

The line I use for pulling data from the DB is:
Code:
set rs = conn.Execute("SELECT * FROM table ORDER BY " & orderBy)


This lets me pull data from the DB with a simple rs("id") or whatever field I choose. Yet a lot of code samples I see don't use this approach and rather have:
Code:
strSQL = "SELECT * FROM table ORDER BY " & orderBy
conn.execute strSQL


What I'd like to know here is, what exactly does the line I'm using do when I call it? To read rs("id") literally, I'm not seeing where the ("id") part ever comes into play. And how would the second example be better over the one I'm using?

I know the code I'm using works great for what I'm doing, but I'd like to know a little more on HOW it works. I also realize these are probably really dense questions and I'm not sure I'll get a reply, but I'd like to thank anyone who takes the time to try explaining it to me.

I also have some questions about updating a database, but we'll wait to see how this goes, first.

Reply With Quote
  #2  
Old March 28th, 2008, 04:49 AM
robsilveruk robsilveruk is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 27 robsilveruk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 39 sec
Reputation Power: 0
Looking for a little clarification on ADO...

Bryce,

I'm sure more informed people here will give a more clear & concise answer, but to start the ball rolling here goes:
There are two ways to access files on a server, the virtual path and physical path. The virtual path is what you type into a browser and the physical path is: C:\folder\sub-folder\filename.txt

So there are times when coding that you want to resolve the virtual path to a physical path and this is where server.mappath comes in to play. Do a search for server.mappath at 4GuysFromRolla for a good article.

You then ask about conn.provider: this tells the connection the type of provider/vendor of the database that you're going to talk to, i.e. MS Access, SQL Server, Oracle. You need this provider when communicating with a DB. The difference between w3schools and your code, is that you mention the provider in the connection string. You can use either approach.

Finally, you ask the difference between set rs = conn.Execute("SELECT * FROM table ORDER BY " & orderBy) and strSQL = "SELECT * FROM table ORDER BY " & orderBy
conn.execute strSQL.
As you can probably guess, they're identical. The second approach is better from a code maintainability perspective, because if you have a long SQL string, with many items in the WHERE clause, then you can build the SQL string up on a line by line basis, rather than one long string in the EXECUTE, e.g.
strSQL = "SELECT FieldA, FieldB, FieldC, FieldD, FieldE, FieldF, FieldG, FieldH, FieldI, FieldJ, FieldK"
strSQL += " WHERE FieldA = FieldB"
strSQL += " AND FieldC = FieldD" etc
is more readable and maintainable than
conn.Execute("SELECT FieldA, FieldB, FieldC, FieldD, FieldE, FieldF, FieldG, FieldH, FieldI, FieldJ, FieldK WHERE FieldA = FieldB AND FieldC = FieldD")

Hope that helps.

Robert

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Looking for a little clarification on ADO...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway