SHARE
Facebook X Pinterest WhatsApp

Querying a Database

Jul 20, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



Ian Stallings
I think this has been covered about a godzillion times but I want to show ASP newbies a clear and easy method to pull data from a database and place it in a webpage.

I think this has been covered about a godzillion times
but I want to show ASP newbies a clear and easy method to
pull data from a database and place it in a webpage.

There are a few objects you can use to get the data from a
database, but I prefer the connection object because it
takes about 3 lines of code to use a SQL statement.

(Before writing the script, make sure you have a DSN to the
DB setup correctly.)

First thing we do is open an active connection to the DB
using the connection object like so:


Set oConn = Server.CreateObject(“ADODB.Connection”)

oConn.Open “DSN=Web;UID=username;PWD=password”


We can then build the SQL statement using:


sql = “SELECT UserName FROM Accounts Where UserName=’madcow'”



We then set the RS object using this line of code:

Set RS = oConn.Execute(sql)



All done! Now that we have the data, we can place it
in our HTML like this:




Keep in mind that this is a very simple example and can be
expanded on greatly. If you have any comments or questions feel
free to drop me a line.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
What Is a Network Policy Server (NPS)? | Essential Guide
Virtual Servers vs. Physical Servers: Comparison and Use Cases
Ray Fernandez
Nov 14, 2023
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.