Solved

Accessing an Access Query that doesn't need parameters passed to it with ASP

Posted on 2003-11-10
8
274 Views
Last Modified: 2010-04-06
I am trying to access a query in an Access database and I need to do it with asp I was wanting the syntax
0
Comment
Question by:Joeba280
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 9719451
Try something like this. Make sure to replace YourAccessFileName and YourQueryName with proper values ...

<%@ Language=VBScript %>
<%option explicit%>
<%
      Response.Buffer = false
%>
<%
      dim oConn, oRs

      sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("YourAccessFileName") & ";User Id=admin;Password=;"

      set oConn = Server.CreateObject("ADODB.Connection")

      Call oConn.Open(sConnectionString)

      set oRs = oConn.Execute("select * from YourQueryName")
%>
<HTML>
<HEAD>
</HEAD>

<BODY>

<%
      Response.Write("<table>")
      while not oRs.EOF
            Response.Write ("<tr>")
            Response.Write ("<td>")
            Response.Write (oRs(0)) 'Here you can also use column name i.e. oRs("ColumnName0")
            Response.Write ("</td>")
            Response.Write ("<td>")
            Response.Write (oRs(1)) 'Here you can also use column name i.e. oRs("ColumnName1")
            Response.Write ("</td>")
            Response.Write ("</tr>")
            Call oRs.MoveNext()
      wend
      Response.Write("</table>")
%>

</BODY>

</HTML>
<%
      set oRs = nothing
      set oConn = nothing
%>
0
 
LVL 1

Author Comment

by:Joeba280
ID: 9719576
I am using a variable for the query name, How would I plug that in here?
0
 
LVL 58

Expert Comment

by:amit_g
ID: 9719582
set oRs = oConn.Execute("select * from " & YourQueryNameVariable)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Joeba280
ID: 9719714
I don't know what is wrong I have put in the code that you gave me but it is now giving me an unspecified error that states on the line where I have the previous connection opening but the funny thing is I have it closed, what could the problem be, I closed the connection and set it equal to nothing.
0
 
LVL 58

Accepted Solution

by:
amit_g earned 250 total points
ID: 9719722
Very difficult to guess without seeing the code. Try this in a new asp file to make sure this code is correct. You can combine this code into the first one after you are certain that it works.
0
 
LVL 1

Author Comment

by:Joeba280
ID: 9719776
I modified it a bit but it does work really appreciate it would you mind looking at the code about that other error. if not thats ok
0
 
LVL 58

Expert Comment

by:amit_g
ID: 9724491
I can give it a try if you post the code :)
0
 
LVL 1

Author Comment

by:Joeba280
ID: 9725677
Well I actually got it working I just need to figure out how to repost the data once something has been selected
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question