Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stupidly Easy ASP/MS Access Question

Status
Not open for further replies.

SPYDERIX

Technical User
Jan 11, 2002
1,899
CA
Hi there,

I don't know ASP, nor do I really want to know ASP, however I need a simple script to do testing with. The test is as follows:
MS Access Name: mytest.mdb
MS Access Table Name: status_test
Fields
ID - Test
1 ASP is connecting to MS Access
(only one row in the db)

I need a simple script to connect to my MS Access db and do the following query: "SELECT * FROM status_test" then output the "test" field onto the page (thus spitting out: ASP is connecting to MS Access)

The connection settings are (from what I gather):
Code:
<%
sub subconnection
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\path\domain\msdb\mytest.mdb"
'conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("msdb/mytest.mdb")
end sub
%>

That connection may need to be in a separate file called "theconnection.asp"

I apologize for my ignorance on this, and YES I HAVE searched google for help and tutorials, but being a PHP programming I really can't wrap my head around ASP. It's just not my thing. Your help is greatly appreciated.

NATE


Got a question? Search G O O G L E first.
 
Doing a select statement to ensure your connected is a little wasteful. I would suggest using the State propoerty of your connection object to check: Response.Write conn.State

However, you will have to use that connection at some point. One of the better resources out there for this (in my opinion) is W3Schools.com. You can see the ADO reference here:
The examples in the examples section use the Open method of a recordset to retrieve the data back, but it is usually more efficient to use the existing connection object to Execute a query, like so:
Code:
Dim strQry, rs
strQry = "SELECT * from status_test"

'execute the SQL query and capture the results
Set rs = conn.Execute(strQuery)

'make sure the recordset isn't empty by checking if it is pointing to EOF
If rs.EOF Then
   Response.Write "No Data returned from query!"
   Response.End  ' similar to php's exit function
End If

'loop through the recordset to return data
Do Until rs.EOF
   'output a value
   Response.Write rs("myFieldName")   'fields can be accessed by name or number

   'increment the row pointer to the next row
   rs.MoveNext
Loop

'clean up
Set rs = Nothing
conn.Close
Set conn = Nothing

Hopefully between the above example and the reference I have posted enough to help, but please let us know if you run into any other issues. ASP is a little different from PHP but you will find it is a little the same as well. They are both procedural languages that allow you to break in and and out code blocks to output HTML and have loosely typed variables. ASP and PHP are much closer together in my mind then ASP and ASP.Net/JSP/Cold Fusion. The biggest differences are that ASP has a much smaller syntax, all include files are included before the script is processed (even if they are in conditional blocks), and while there are often multiple ways to do things they aren't on the magnitude of PHP's 50 ways to do any given task.

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top