Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Database Interaction

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,453
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Database Interaction
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Database Interaction - 10/26/2001 2:18:07 PM   
  PeteCan

 

Posts: 1
Score: 0
Joined: 10/26/2001
From:
Status: offline
I have created an access database which I want to interact with from the web. On the web page there is a text box, user types in a name and I need to add this to the SQL statement but am unsure how to do it, here's a sample of what I've got so far :

<html>

<head>
<title>New Page 1</title>
<%@ Language = VBscript %>
<%
'Get variables from the querystring.
typedname=myform.thebox.value

'Construct SQL statment
SQLCARNAME="SELECT forename FROM Staffnames "
SQLCARNAME=SQLCARNAME & "WHERE surname= " & typedname

'Open database connection and execute SQL statment.
'Load recordset into variable named carname
set conncarname = server.createobject("ADODB.Connection")
conncarname.open "DCOINFO"
set carname=conncarname.execute(SQLCARNAME)
%>
</head>

<body>

<form name="myform">
<p><input type="Text" name="thebox" size="25"><br>
<input type="Submit" value="Take A Look" align="MIDDLE"> </p>
</form>
</body>
</html>
 
 
Post #: 1
 
 Re: Database Interaction - 10/26/2001 6:45:46 PM   
  imav8n

 

Posts: 95
Score: 0
Joined: 7/3/2001
From: USA
Status: offline
Try this (page name is: page3.asp) :

<%@ Language = VBscript %>
<html>
<head>
<title>New Page 1</title>
</head>

<%
'Get variables from the querystring.
typedname = Request.QueryString("thebox")

if typedname <> null then

'Open database connection
set conncarname = server.createobject("ADODB.Connection")
conncarname.ConnectionString = "DSN=DCOINFO"
conncarname.open

'Create the SQL Statement
SQLCARNAME="SELECT forename FROM Staffnames WHERE surname=" & typedname & ";"

'Create the RecordSet and open with SQL statement
Set CarNameRS = CreateObject("ADODB.Recordset")
CarNameRS.open SQLCARNAME, conncarname

end if
%>

<body>
<form name="myform" action=page3.asp method=get>
<p><input type="Text" name="thebox" size="25"><br>
<input type="Submit" value="Take A Look" align="MIDDLE"> </p>
</form>

Forename is: <% CarNameRS("forename") %>
</body>
</html>


*************************************************************

When this page opens, it checks to see if the variable is null...if it is (meaning the first time that it's called) then all the page displays is the form field to enter a name. When you hit submit, the form submits the textfield to the same page, which searches the database and displays the info.

Let me know if you need any help with this...


~imav8n
Failure is not an option.....it comes bundled with the software.

(in reply to PeteCan)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Database Interaction Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts