Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Script error from a user that claimed it to work

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
Evert Jor
Asked:
Evert Jor
  • 3
  • 2
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Evert JorDVM/ResearcherAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Evert JorDVM/ResearcherAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, thanks for the points.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now