www.fingertip.page.tl or www.fingertip.us.tt - ASP-4
   
www.fingertip.us.tt
  Index
  Free WebHost&DNS
  Hardware&Networking
  Red Hat Enterprise Linux 5
  Active Server Page2.0
  => Active Server Pages2.0
  => ASP-1
  => ASP-1.1
  => ASP-2
  => ASP-3
  => ASP-4
  => ASP-5
  Database Coding Standards
  .Net Platform
  Link Website
  Online Game
  Satellite Image Home
  Download Toolbar
  Other
  WebMaster
  Counter
  SiteMap
  Guestbook
  To Contact Us
  IT People
  Website Grade
  Learn English
  Donate Money
  Comrades
  Free Dictionary
  VaaHOO

www.e-comwebsite.blogspot.com
File Object
<html>
<body>

<%
dim fs, f
set fs=Server.CreateObject
("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt
was created on: " &
f.DateCreated)
set f=nothing
set fs=nothing
%>


</body>
</html>
<html>
<body>

<%
dim fs, f
set fs=Server.CreateObject
("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt
was last modified on: " &
f.DateLastModified)
set f=nothing
set fs=nothing
%>


</body>
</html>
<html>
<body>

<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was last accessed on: " & f.DateLastAccessed)
set f=nothing
set fs=nothing
%>


</body>
</html>
 
<html>
<body>

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The attributes of the file testread.txt are: " & f.Attributes)
set f=nothing
set fs=nothing
%>


</body>
</html>
 
Dictionary Object
<html>
<body>

<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
if d.Exists("n")= true then
    Response.Write("Key exists.")
else
    Response.Write("Key does not exist.")
end if
set d=nothing
%>


</body>
</html>
 
 
<html>
<body>

<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"

Response.Write("<p>The values of the items are:</p>")
a=d.Items
for i = 0 To d.Count -1
    s = s & a(i) & "<br>"
next
Response.Write(s)

set d=nothing
%>


</body>
</html>
<html>
<body>

<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("<p>The value of the keys are:</p>")
a=d.Keys
for i = 0 To d.Count -1
    s = s & a(i) & "<br>"
next
Response.Write(s)
set d=nothing
%>


</body>
</html>
 
 
<html>
<body>

<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The value of the item n is: " & d.item("n"))
set d=nothing
%>


</body>
</html>
<html>
<body>

<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
d.Key("i") = "it"
Response.Write("The key i has been set to it, and the value is: " & d.Item("it"))
set d=nothing
%>


</body>
</html>
<html>
<body>

<%
dim d, a, s, i
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The number of key/item pairs is: " & d.Count)
set d=nothing
%>


</body>
</html>
 
 
AdRotator
<html>
<body>

<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
adrotator.Border="2"
Response.Write(adrotator.GetAdvertisement("text/advertisements.txt"))
%>


<p>
NOTE: Because images are changed randomly, and because this page has few images to choose from, it will often display the same advertisement twice in a row.
</p>

<p>
<a href="text/advertisements.txt">
<img border="0" src="../images/btn_view_text.gif">
</a>
</p>

</body>
</html>
 
<%
url=Request.QueryString("url")
If url<>"" then Response.Redirect(url)
%>

<html>
<body>

<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
adrotator.TargetFrame="target='_blank'"
response.write(adrotator.GetAdvertisement("text/advertisements2.txt"))
%>


<p>
NOTE: Because images are changed randomly, and because this page has few images to choose from, it will
often display the same advertisement twice in a row.
</p>

<p>
<a href="text/advertisements2.txt">
<img border="0" src="../images/btn_view_text.gif"></a>
</p>
</body>
</html>
 
 
Browser Capabilities
<html>
<body>

<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>


<table border="1" width="65%">
   <tr>
     <td width="52%">Client OS</td>
     <td width="48%"><%=MyBrow.platform%></td>
   </tr>
   <tr>
     <td >Web Browser</td>
     <td ><%=MyBrow.browser%></td>
   </tr>
   <tr>
     <td>Browser version</td>
     <td><%=MyBrow.version%></td>
   </tr>
   <tr>
     <td>Frame support?</td>
     <td><%=MyBrow.frames%></td>
   </tr>
   <tr>
     <td>Table support?</td>
     <td><%=MyBrow.tables%></td>
   </tr>
   <tr>
     <td>Sound support?</td>
     <td><%=MyBrow.backgroundsounds%></td>
   </tr>
   <tr>
     <td>Cookies support?</td>
     <td><%=MyBrow.cookies%></td>
   </tr>
   <tr>
     <td>VBScript support?</td>
     <td><%=MyBrow.vbscript%></td>
   </tr>
   <tr>
     <td>JavaScript support?</td>
     <td><%=MyBrow.javascript%></td>
   </tr>
</table>

</body>
</html>







 
ContentRotator
<html>
<body>

<p><b>Note:</b> This example won't work because ASP 3.0 is not installed on our server.
</p>

<p>
<a href="demo_textads.asp"><img border="0" src="../images/btn_view_text.gif"></a>
</p>
<%
set cr=server.createobject("MSWC.ContentRotator")
response.write(cr.ChooseContent("text/textads.txt"))
%>


<p>
NOTE: Because the content strings are changed randomly in the text file, and this page has only four content strings to choose from, sometimes the page will display the same content strings twice in a row.
</p>

</body>
</html>
 
 
Content Linking
<html>
<body>

<p>
The example below builds a table of contents.
</p>

<%
dim c
dim i
set nl=server.createobject("MSWC.Nextlink")
c = nl.GetListCount("textlinks.txt")
i = 1
%>

<ul>
<%do while (i <= c) %>
<li><a href="<%=nl.GetNthURL("textlinks.txt", i)%>">
<%=nl.GetNthDescription("textlinks.txt", i)%></a>
<%
i = (i + 1)
loop
%>

</ul>
<p>
The text file contains a list of page urls
and link descriptions. It contains one line of text for each page. Note that the url and
description MUST be separated by the TAB character.
</p>
<p>
<a href="text/links.txt"><img border="0" src="../images/btn_view_text.gif"></a>
</p>
</body>
</html>
<html>
<body>

<h1>
This is page 1!
</h1>

<%
Set nl=Server.CreateObject("MSWC.NextLink")
If (nl.GetListIndex("text/links2.txt")>1) Then
%>

<a href="<%Response.Write(nl.GetPreviousURL("text/links2.txt"))%>">Previous Page</a>
<%End If%>

<a href="<%Response.Write(nl.GetNextURL("text/links2.txt"))%>">Next Page</a>

<p>The example uses the Content Linking Component
to navigate between the pages in a text file.</p>

<p>
<a href="text/links2.txt"><img border="0" src="../images/btn_view_text.gif"></a>
</p>
</body>
</html>

 
 
 
 
 
 
 
 
 
 
 
 
 

ADO
 
ADO Tutorial
In our ADO tutorial you will learn about ADO, and how to use ADO to access databases from your Web. Start Learning ADO!
 
 
ADO can be used to access databases from your web pages.

What you should already know
Before you continue you should have a basic understanding of the following:
  • WWW, HTML and the basics of building Web pages
  • Active Server Pages (ASP)
  • Structured Query Language (SQL)
If you want to study these subjects first, go to our Home Page

What is ADO?
  • ADO is a Microsoft technology
  • ADO stands for ActiveX Data Objects
  • ADO is a Microsoft Active-X component
  • ADO is automatically installed with Microsoft IIS
  • ADO is a programming interface to access data in a database

Accessing a Database from an ASP Page
The common way to access a database from inside an ASP page is to:
1.       Create an ADO connection to a database
2.       Open the database connection
3.       Create an ADO recordset
4.       Open the recordset
5.       Extract the data you need from the recordset
6.       Close the recordset
7.       Close the connection
 
 
 
 

 
 
ADO Introduction
This chapter explains what ADO is, and how it can be used.
 
 
 
 
 
 
ADO Database Connection
This chapter explains how to connect to a database using ADO. 
 
Before a database can be accessed from a web page, a database connection has to be established.

Create a DSN-less Database Connection
The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection can be used against any Microsoft Access database on your web site.
If you have a database called "northwind.mdb" located in a web directory like "c:/webdata/", you can connect to the database with the following ASP code:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>
Note, from the example above, that you have to specify the Microsoft Access database driver (Provider) and the physical path to the database on your computer.

Create an ODBC Database Connection
If you have an ODBC database called "northwind" you can connect to the database with the following ASP code:
<%
set conn=Server.CreateObject("ADODB.Connection") 
conn.Open "northwind"
%>
With an ODBC connection, you can connect to any database, on any computer in your network, as long as an ODBC connection is available.

An ODBC Connection to a MS Access Database
Here is how to create a connection to a MS Access Database: 
1.       Open the ODBC icon in your Control Panel.
2.       Choose the System DSN tab.
3.       Click on Add in the System DSN tab.
4.       Select the Microsoft Access Driver. Click Finish.
5.       In the next screen, click Select to locate the database.
6.       Give the database a Data Source Name (DSN).
7.       Click OK.
 
 
 
 
 
 
ADO Recordset
This chapter explains how to access an ADO Recordset. 
 
ADO Recordset
 

To be able to read database data, the data must first be loaded into a recordset. 

Create an ADO Table Recordset
After an ADO Database Connection has been created, as demonstrated in the previous chapter, it is possible to create an ADO Recordset.  
Suppose we have a database named "Northwind", we can get access to the "Customers" table inside the database with the following lines:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Customers", conn
%>
 

Create an ADO SQL Recordset
We can also get access to the data in the "Customers" table using SQL:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
%>
 

Extract Data from the Recordset
After a recordset is opened, we can extract data from recordset.  
Suppose we have a database named "Northwind", we can get access to the "Customers" table inside the database with the following lines:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
for each x in rs.fields
   response.write(x.name)
   response.write(" = ")
   response.write(x.value)
next
%>
 
 
 
ADO Display
This chapter explains the most common way to display data from an ADO Recordset. 
 
 
 
Display the Field Names and Field Values
We have a database named "Northwind" and we want to display the data from the "Customers" table (remember to save the file with an .asp extension):
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
do until rs.EOF
 for each x in rs.Fields
    Response.Write(x.name)
    Response.Write(" = ")
    Response.Write(x.value & "<br />") 
  next
 Response.Write("<br />")
 rs.MoveNext
loop
rs.close
conn.close
%>
</body>
</html>
 
 
 
 
ADO Query
This chapter explains how to use SQL to filter an ADO Recordset. 
ADO Sort
This chapter explains how to use SQL to sort an ADO Recordset. 
ADO Add
This chapter explains how to use the SQL INSERT INTO command to add a record to a table in a database. 
 
 
 
Add a Record to a Table in a Database
We want to add a new record to the Customers table in the Northwind database. We first create a form that contains the fields we want to collect data from:
<html>
<body>
<form method="post" action="demo_add.asp">
<table>
<tr>
<td>CustomerID:</td>
<td><input name="custid"></td>
</tr><tr>
<td>Company Name:</td>
<td><input name="compname"></td>
</tr><tr>
<td>Contact Name:</td>
<td><input name="contname"></td>
</tr><tr>
<td>Address:</td>
<td><input name="address"></td>
</tr><tr>
<td>City:</td>
<td><input name="city"></td>
</tr><tr>
<td>Postal Code:</td>
<td><input name="postcode"></td>
</tr><tr>
<td>Country:</td>
<td><input name="country"></td>
</tr>
</table>
<br /><br />
<input type="submit" value="Add New"> 
<input type="reset" value="Cancel">
</form>
</body>
</html>
When the user presses the submit button the form is sent to a file called "demo_add.asp". The "demo_add.asp" file contains the code that will add a new record to the Customers table:
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
sql="INSERT INTO customers (customerID,companyname,"
sql=sql & "contactname,address,city,postalcode,country)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("custid") & "',"
sql=sql & "'" & Request.Form("compname") & "',"
sql=sql & "'" & Request.Form("contname") & "',"
sql=sql & "'" & Request.Form("address") & "',"
sql=sql & "'" & Request.Form("city") & "',"
sql=sql & "'" & Request.Form("postcode") & "',"
sql=sql & "'" & Request.Form("country") & "')"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
 Response.Write("No update permissions!")
else 
  Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
 
</body>
</html>
 

Important
If you use the SQL INSERT command be aware of the following:
  • If the table contains a primary key, make sure to append a unique, non-Null value to the primary key field (if not, the provider may not append the record, or an error occurs)
  • If the table contains an AutoNumber field, do not include this field in the SQL INSERT command (the value of this field will be taken care of automatically by the provider)

What about Fields With no Data?
In a MS Access database, you can enter zero-length strings ("") in Text, Hyperlink, and Memo fields IF you set the AllowZeroLength property to Yes.
Note: Not all databases support zero-length strings and may cause an error when a record with blank fields is added. It is important to check what data types your database supports.


Locations of visitors to this page 





Add comment to this page:
Your Name:
Your Email address:
Your website URL:
Your message:

   

=> Do you also want a homepage for free? Then click here! <=