?
Solved

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

Posted on 2003-11-10
8
Medium Priority
?
284 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
Independent Software Vendors: 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

807 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