View Full Version : Beginner to ASP
rhuarc
06-25-2003, 01:28 PM
Hello
I am new to ASP and would like to start a simple test.
Could someone assist me on the code to connect a access 97 database to a web server.
I just want to be able to type in and name and then hit enter and for it to search for that name in my databse and then bring up the appropiate info relating to that name.
Your help would be much appreciated.
Cheers
Rhuarc
Vimal
06-26-2003, 12:12 AM
Here's a simple code for you. Hope it will help.
<% @Language= "VBScript" %>
<%
Option Explicit
%>
<html>
<head>
<title>Your Page</title>
</head>
<form method="POST" action="yourpage.asp" <p align="center"><font size="2"><font color="#000000"><b>Name<font color="#000000">: </font></b><input type="text" name="namebox" size="20"><input type="submit" value="Submit" name="B1"></p>
<p align="center" style="line-height: 100%; margin-top: -6; margin-bottom: -6"> </p>
</form>
<%
'DECLARE ALL LOCAL VARIABLES
Dim Conn
Dim connrcs
Dim strConn
Dim strSQL
Dim strURL
Dim sPath
Dim namebox
'SET CONNECTION TO LOCAL VARIABLE
sPath = Server.MapPath("DBNAME.mdb")
strConn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & sPath
'Retrieve the value in search box
namebox = Request.form("namebox")
'Open connection to the DB
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open strConn
Set connrcs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * from TABLENAME where name = '" & namebox & "'"
connrcs.open strSQL, conn
conn.Execute(strSQL)
%>
<%If namebox <> "" Then%>
<table border="1" align="center" height="1" width="50%">
<tr>
<th height="1" align="center" width="25%">
<font color="black"><font size="2"><div align="center">Field 1</div></font>
</th>
<th height="1" align="center" width="25%">
<font color="black"><font size="2"><div align="center">Field 2</div></font>
</th>
<th height="1" align="center" width="25%">
<font color="black"><font size="2"><div align="center">Field 3</div></font>
</th>
<th height="1" align="center" width="25%">
<font color="black"><font size="2"><div align="center">Field 4</div></font>
</th>
</tr>
<%
While Not connrcs.EOF
Response.Write "<td><font size=2><center>" & connrcs(1) & "</td></font></center>"
Response.Write "<td><font size=2><center>" & connrcs(2) & "</td></font></center>"
Response.Write "<td><font size=2><center>" & connrcs(3) & "</td></font></center>"
Response.Write "<td><font size=2><center>" & connrcs(4) & "</td></font></center>"
Response.Write "</tr>" & vbCrLf
connrcs.MoveNext
Wend
connrcs.close
Conn.close
Set connrcs = Nothing
Set Conn = Nothing
%>
</table>
<%
End if
madg3rr
06-26-2003, 12:13 AM
u could try dis website... u can try implemeting them in ur simple test. hope dis can help ya...
http://www.aspin.com/home/tutorial/database/search
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.