Solved

Script error from a user that claimed it to work

Posted on 2013-01-20
5
279 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 82

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 82

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 82

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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.

743 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

13 Experts available now in Live!

Get 1:1 Help Now