_Server-Side Scripting in Visual Basic_
by Al Williams
Example 1:
(a)
Copyright 1997 by Al Williams
(b)
A Demo Page
Welcome to this meaningless page.
Example 2:
(a)
The first few Fibonacci numbers:
<% n1=0 n2=1
for i= 1 to 100 %>
Number <%=I %>: <%= n1+n2 %>
<% old=n1
n1=n2
n2=old+n2
next %>
(b)
<% If flag=True %>
You are authorized to proceed_
<% else %>
Unauthorized Access Attempted!
<% end if %>
Listing One
Report Your Sightings!
<% if Request("Content_Length")=0 then %>
Report your King Sightings Here!
<%else %>
<% ' Using record set which is easy, but an Insert would
' have better performance (see DDJFIND.ASP)
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "KingSight","guest",""
set RS=Server.CreateObject("ADODB.RecordSet")
Conn.BeginTrans ' start a unit of work
rs.Open "Sighting", Conn, adOpenStatic, adLockOptimistic
rs.AddNew ' new record
rs("Date")=CDate(Request("KDate"))
if Request("Before")="on" then
rs("Before")=-1
else
rs("Before")=0
end if
rs("Location")=Request("Loc")
rs("Name")=Request("Name")
rs("Comment")=Request("Comment")
rs("subtime")=now
rs.Update
Conn.CommitTrans
rs.Close
Conn.Close
%>
Thanks for your report
Thank you very much!
Click here to view recent sightings!
<% end if %>
Listing Two
Find the King
Recent King Sightings:
<% Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "KingSight","guest",""
' Execute SQL select
SQL="Select * from Sighting order by date desc"
set RS = Conn.Execute(SQL)
%>
<% For i = 0 to RS.Fields.Count - 2 %>
<%= RS(i).Name %> |
<% Next %>
<% Do While Not RS.EOF %>
<% For i = 0 to RS.Fields.Count - 2 %>
<% if RS(i).Name<>"Before" then %>
<%= RS(i) %>
<% else %>
<% if RS(i)=0 then %>
N
<% else %>
Y
<% end if %>
<% end if %>
|
<% Next %>
<%
RS.MoveNext
Loop
RS.Close
Conn.Close
%>
Be sure to add your sightings by clicking
here.