Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Retrieving data from Excel
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Retrieving data from Excel

 Post Reply Post Reply
Author
taurz View Drop Down
Newbie
Newbie
Avatar

Joined: 31 May 2003
Location: Qatar
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote taurz Quote  Post ReplyReply Direct Link To This Post Topic: Retrieving data from Excel
    Posted: 31 May 2003 at 2:34am

I have the following code to retrieve info from an Excel file through ASP. 

-----search.htm-------

 

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search Farm</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" height="237">
  <tr>
    <td width="14%" height="237">&nbsp;</td>
    <td width="62%" height="237" valign="top">
   <form method="POST" action="searchfarm2.asp" target="foo" onsubmit="window.open('', 'foo', 'width=600,height=300,status=yes,resizable=no,scrollbars=no')">
  <!--   <form method="POST" action="searchfarm2.asp">-->
      <p><font face="Arial" size="2">Farm </font> <input type="text" name="T1" size="20"></p>
      <p><input type="submit" value="Submit" name="B1"></p>
    </form>
    </td>
    <td width="24%" height="237">&nbsp;</td>
  </tr>
</table>

</body>

</html>

 

 

-----searchfarm2.asp----

<html>
<head>


<META http-equiv=Content-Type content="text/html; charset=windows-1256">
<title>Farms Database</title>
<style>
th {background:black;color:white}
.value {background:white;color:black}
.count {background:silver;color:black}
</style>
</head>

<body bgcolor=white >

<%

varfarm=request.form("T1")

 

 

' Change the following variables to reflect
' the names and locations for your file and
' table(s)
PATH="D:\agrdb\Update\tables\"
'PATH="D:\work\"
FILE="FARMOWN2.xls"
TABLE="farms"
' Change this SQL statement as required
SQL="SELECT * FROM farms WHERE Farm_no=" & varfarm
DRIVER="{Microsoft Excel Driver (*.xls)}"
DB="DBQ=" & PATH & FILE & ";"
DB= DB & "DefaultDir=" & PATH & ";"
DB= DB & "Driver=" & DRIVER & ";"
DB = DB & "FIL=excel 5.0;ReadOnly=1;"
Set DataConn=Server.CreateObject("ADODB.Connection")
DataConn.ConnectionTimeout = 15
DataConn.CommandTimeout = 30
DataConn.Open DB
Set RS_item = DataConn.Execute(SQL)
%>
<%
response.write "<table border cellspacing=0><tr>"
if RS_item.EOF then
     response.write "    <td colspan=10>No Records found</td></table>"
else
    response.write "</table>"
 response.write "<p><font face=Arial size=1>Record no. :"%>
 <%=RS_item("no") %>
<% response.write "</font></p>"
 response.write "<p><font face=Arial size=2>Details of Farm No. <B>"%>
 <%=RS_item("Farm_no")%>
 <%response.write "</B></font></p>"
  response.write "<table border=0 cellpadding=3 cellspacing=0 style='border-collapse: collapse' bordercolor=#111111 width=100% id=AutoNumber1>"
response.write "  <tr>"
response.write "    <td width='8%'>&nbsp;</td>"
response.write "   <td width='25%' valign=top><font face=Arial size=2>Owner</font></td>"
response.write "    <td width='67%'>"%>
<%=RS_item("Ename")%>
<%response.write"<br>"%>
<%=RS_item("Aname")%>
<%response.write "    </td>"
response.write "  </tr>"
response.write "  <tr>"
response.write "    <td width='8%'>&nbsp;</td>"
response.write "    <td width='25%' valign='top'><font face='Arial' size='2'>Agricultural District</font></td>"
response.write "    <td width='67%'><p>"%>
<%=RS_item("Dist")%>
<%response.write"<br>"%>
<%=RS_item("Edist")%>   
<%response.write "    </td>"
response.write "  </tr>"
response.write "  <tr>"
response.write "    <td width='8%'>&nbsp;</td>"
response.write "    <td width='25%' valign='top'><font face='Arial' size='2'>Location</font></td>"
response.write "    <td width='67%'>"%>
 <%=RS_item("AArea")%>
 <%response.write"</td>"
response.write "  </tr>"
response.write "  <tr>"
response.write "    <td width='8%'>&nbsp;</td>"
response.write "    <td width='25%' valign='top'><font face='Arial' size='2'>Area (Donum)</font></td>"
response.write "    <td width='67%'> "%>
<%=RS_item("GArea")%>
<%response.write"</td>"
response.write "  </tr>"
response.write "</table>"

 

-------------------------

The code executes fine the first time, but when i give a second number to the excel file to retrieve another data, it gives an error in connection.  Any ideas??

thanks

Back to Top
Bullschmidt View Drop Down
Groupie
Groupie


Joined: 31 May 2003
Location: United States
Status: Offline
Points: 72
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bullschmidt Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2003 at 10:55pm
J. Paul Schmidt, Freelance ASP Web Developer
www.Bullschmidt.com
Classic ASP Design Tips, ASP Web Database Sample (Freely Downloadable)
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.