How To Query a MS Access Database Using ASPSeptember 30th, 2008 · No Comments
This tutorial will show you how to open a connection to a MS Access database and perform a SQL query.
I will not go into details about creating a MS Access database, but for this post I’ve used a very simple structure made of one table (mytable) with two fields (id and data). Of course the first you want to do is to upload your database to your server using FTP. Then you’ll need to create an ASP script using a text editor like Notepad for instance. Ok let’s go! 1. Start your script by creating the variables that we’re going to use: <html> <head><title>Querying a MS Access Database</title></head> <body> <% Dim adoCon 'Holds the Database Connection Object Dim rsTable 'Holds the recordset for the records in the database Dim strSQL 'Holds the SQL query to query the database 2. Next we need to create a database connection object using the ADO (ActiveX Data Objects): Set adoCon = Server.CreateObject("ADODB.Connection")
3. Now we’re going to open the database. Note that you must specify the path and the name of your own database here: adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("mydatabase.mdb")
4. Create an ADO recordset object: Set rsTable = Server.CreateObject("ADODB.Recordset")
5. We’re now going to set our SQL query string: strSQL = "select * from mytable;" 6. Let’s open the recordset and run our SQL query: rsTable.Open strSQL,adoCon 7. Now you need to create a loop that will go through the recordset: Do While not rsTable.EOF
Response.Write(rsTable("id"))
Response.Write("<br />")
Response.Write(rsTable("data"))
Response.Write("<br /><br />")
rsTable.MoveNext
Loop
8. And finally we’ll close the recordset, reset the server objects and close the scripting tag: rsTable.Close Set rsTable = Nothing Set adoCon = Nothing %> </body></html> When you’re done, simply upload your ASP script to your server and use your web browser to see the result. Of course, if you’re going to store a large amount of data or if your website gets a lot of traffic, you’re better off with a database server such MS SQL or MySQL as it will deliver a lot more speed and performance. LinksRelated PostsPosted in Tutorials · Windows Server | No Comments |
Popular PostsLatest PostsLatest Deals & CouponsRecent Comments
Hosting ReviewsRecent WebmastersTag Cloud
1and1
apache
bluehost
centos
cheap web hosting
control panel
coupon
coupon code
cpanel
dedicated servers
dreamhost
godaddy
green web hosting
hostdime
hostgator
hostpapa
iis
inmotion hosting
knownhost
linux
lunarpages
mysql
openx
php
reseller hosting
shared hosting
system administration
vps
web hosting
web hosting comparison
Web Hosting Comparisons
whm
windows
windows 2008
wordpress
|
|||||||||
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment