Solved

Script error from a user that claimed it to work

Posted on 2013-01-20
5
280 Views
Last Modified: 2013-11-19
Hi.

I have a problem with web page for retrieving data from an access database.
The original post claimed it was working, but I only get the first record and it doesn't refresh when I use the combo-box to retrieve new data.

To me it seems to be the where clasue that isn't working. I get the correct data from the request.querystring statement, but it only returns the data from the first record in the database. The original post was ID: 20443483.

My code is as follows:

<%response.buffer=true%>
<%

Set oConnection = Server.CreateObject("ADODB.Connection")
oConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:/inetpub/db/dbimgs21.accdb;Persist Security Info=False"
'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:/inetpub/db/dbimgs21.accdb;Mode=Read|Share Deny None;Persist Security Info=False

set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM Table1"
rs.Open sql, oConnection

%>
<html>
<head>
<title>My plants</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
</head>
<script language="Javascript">
function doSel(obj)
{
  for (i = 0; i < obj.length; i++)
     if (obj[i].selected == true)
       eval(obj[i].value);
}

</script>
<body>
<select name="Ref_ID" onchange="doSel(this)">
<option value="">Vennligst velg en art</option>
<%Do while not(rs.eof)%>
<option value="location.href='dropdown.asp?id=<%=rs("ID")%>'" <%if request.querystring("id")=rs("ID") then response.write "selected" end if%>><%=rs("ID")%></option>
<%
rs.movenext
loop
%>
</select>

<%if request.querystring("id") <> "" then
set rs1 = Server.CreateObject("ADODB.Recordset")
sql2 = "SELECT * FROM Table1 WHERE ID = '"& request.querystring("id") &"'"
rs1.Open sql, oConnection

%>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td>City</td>
    <td> 
<input type="text" name="txtcity" value="<%=rs1("City")%>">
    </td>
 </tr>
 <tr>
   <td>State</td>
   <td>
      <input type="text" name="txtstate" value="<%=rs1("State")%>">
    </td>
 </tr>
</table>
<%rs1.Close()
Set rs1 = Nothing
end if
%>

<%
rs.Close()
%>
</body>

</html>

Open in new window

0
Comment
Question by:EvertJor
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 38798902
Lines 40 and 41 were wrong.

<%response.buffer=true%>
<%

Set oConnection = Server.CreateObject("ADODB.Connection")
oConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:/inetpub/db/dbimgs21.accdb;Persist Security Info=False"
'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:/inetpub/db/dbimgs21.accdb;Mode=Read|Share Deny None;Persist Security Info=False

set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM Table1"
rs.Open sql, oConnection

%>
<html>
<head>
<title>My plants</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
</head>
<script language="Javascript">
function doSel(obj)
{
  for (i = 0; i < obj.length; i++)
     if (obj[i].selected == true)
       eval(obj[i].value);
}

</script>
<body>
<select name="Ref_ID" onchange="doSel(this)">
<option value="">Vennligst velg en art</option>
<%Do while not(rs.eof)%>
<option value="location.href='dropdown.asp?id=<%=rs("ID")%>'" <%if request.querystring("id")=rs("ID") then response.write "selected" end if%>><%=rs("ID")%></option>
<%
rs.movenext
loop
%>
</select>

<%if request.querystring("id") <> "" then
set rs1 = Server.CreateObject("ADODB.Recordset")
sql2 = "SELECT * FROM Table1 WHERE ID = "& request.querystring("id")
rs1.Open sql2, oConnection

%>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td>City</td>
    <td> 
<input type="text" name="txtcity" value="<%=rs1("City")%>">
    </td>
 </tr>
 <tr>
   <td>State</td>
   <td>
      <input type="text" name="txtstate" value="<%=rs1("State")%>">
    </td>
 </tr>
</table>
<%rs1.Close()
Set rs1 = Nothing
end if
%>

<%
rs.Close()
%>
</body>

</html>

Open in new window

0
 

Author Comment

by:EvertJor
ID: 38802132
Thanks DaveBaldwin.

This works on a single page, but when I try to use "include" statements it doesn't.
I've reviewed several posts regarding this issue. According to Microsoft the following should work:
"To work around this issue, use one of the following methods.
Method 1: Use the #include virtual statement together with an absolute file path

To work around this issue, use the #include virtual statement together with an absolute file path in the Test.asp Web page. Consider the following code examples:
The following line of code does not work.
<!-- #include virtual ="../Date.asp" -->
The follow line of code works.
<!-- #include virtual ="Samples/Includes/Date.asp" -->
Method 2: Use the #include file statement together with a relative file path

To work around this issue, use the #include file statement together with a relative file path in the Test.asp Web page. Consider the following code samples:
The following line of code does not work.
<!-- #include virtual ="../Date.asp" -->
The following line of code does work.
<!-- #include file ="..\Date.asp -->
Note By default, parent paths are disabled in IIS 6. To enable parent paths, you must manually set the AspEnableParentPaths property in the metabase to TRUE."

However it doesn't.

I get error |ASP_0126|Cannot_find_the_include_file

Any ideas what may be wrong?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38802313
Ok, that's confusing.  What you posted is a 'complete' though poorly formatted page.  What do include statements of any kind have to do with it?  What are you trying to do?
0
 

Author Comment

by:EvertJor
ID: 38804932
Hi.

I was trying to include the dropdown.asp page in another main.asp page.

Now I figured out what was wrong: Line 31 in the code have to point to the main page.
Thanks for your help!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38806631
You're welcome, thanks for the points.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now