Servers Querying a Database

Querying a Database




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.

Latest Posts

Get-MsolUser PowerShell Attributes & Properties

This article has been updated for 2020. Please note that WAAD was retired in 2018, but the cmdlets listed in this article are still...

Microsoft Azure PowerShell Scripts and Commands

Using PowerShell scripts and commands for quickly executing tasks in Windows operating systems offers a number of benefits over traditional scripting languages, such as...

Microsoft Hyper V Review

Microsoft Hyper-V: The Bottom line Microsoft Hyper-V lagged behind VMware's virtualization tool, one of the most popular tools in the space, when it was first...

Best Cloud Based Services & Companies

Any company that’s delayed introducing cloud-based software into their infrastructure needs to consider leveraging these new technologies to reap all the benefits cloud computing...

Best Load Balancers for 2020

The best load balancers are able to provide either hardware or software-based load balancing to ensure maximum service availability by offering network traffic distribution...

Related Stories