Address Book Application Source Code

See Also   

The following code is the complete source code for the Address Book sample application.

<HTML>
<HEAD>
<TITLE>Corporate Address Book</TITLE>
</HEAD>

<!--
   Purpose:   To provide a company directory search service for Web users.
   Written By:   Microsoft Remote Data Service Team, Microsoft Corp.
   Date:   April, 1997
-->

<BODY BACKGROUND="Arcadia.gif" LANGUAGE="VBScript" onload="Load">
<tr>
   <td align="center" width="40%">
      <table border="2" cellpadding="7" cellspacing="7">
         <tr>
            <td width="100%"><font color="#160B5A"><font
            size="4"><strong>Arcadia Bay Corporate Phone
            Directory</strong></font></font></td>
         </tr>
      </table>
      </td>
</tr>

<hr>
<h2><font color = "#160B5A">Search Parameters</h2>
<h5><font color = "#160B5A">Please enter one or more search patterns and press FIND to search.</h5>

<FONT COLOR = "#160B5A"><B>

<PRE> First Name   <INPUT NAME=SFirst SIZE=30> </PRE>

<PRE> Last Name  <INPUT NAME=SLast  SIZE=30> </PRE>

<PRE> Title    <INPUT NAME=STitle SIZE=30> </PRE>

<PRE> E-mail Alias <INPUT NAME=SEmail SIZE=30> </PRE>

<!-- 
   Command button options:
   -----------------------
   Find      Submit a search request to the database.
   Clear      Clear the QBE fields (labor saving function only).
   Update Profile   Send updated "address profile" back to the database.
   Cancel Changes   Undo all changes since the last Update Profile.
-->

<INPUT TYPE=BUTTON NAME="Find"    VALUE="Find">
<INPUT TYPE=BUTTON NAME="Clear"    VALUE="Clear">
<INPUT TYPE=BUTTON NAME="Update"    VALUE="Update Profile">
<INPUT TYPE=BUTTON NAME="Cancel"    VALUE="Cancel Changes">

<hr>
<h2><font color = "#400040">Search Results</h2>
</B>
<br>

<!-- 
   This Sheridan DataGrid control (SGrid) is initialized to
   allow changes to the data - these changes will be saved
   to the database when the Update Profile button is pressed. 
-->

<Object CLASSID="clsid:AC05DC80-7DF1-11d0-839E-00A024A94B3A"
   CODEBASE="http://<%=Request.ServerVariables("SERVER_NAME")%>/MSADC/Samples/ssdatb32.cab"
   ID=GRID1 
    datasrc=#SControl 
    HEIGHT=125 
    WIDTH=495>
   <PARAM NAME="AllowAddNew" VALUE="TRUE">
   <PARAM NAME="AllowDelete" VALUE="TRUE">
   <PARAM NAME="AllowUpdate" VALUE="TRUE">
   <PARAM NAME="BackColor"   VALUE="-2147483643">
   <PARAM NAME="BackColorOdd"  VALUE="-2147483643">
   <PARAM NAME="ForeColorEven" VALUE="0">
</OBJECT>

<br>
<br>
<INPUT TYPE=BUTTON NAME="First"    VALUE="First">
<INPUT TYPE=BUTTON NAME="Prev"    VALUE="Previous">
<INPUT TYPE=BUTTON NAME="Next"   VALUE="Next">
<INPUT TYPE=BUTTON NAME="Last"   VALUE="Last">
<hr>


<!-- Non-visual controls - RDS.DataControl -->

<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
   ID=SControl
   WIDTH=1 HEIGHT=1>
   <PARAM NAME="SERVER" VALUE="http://<%=Request.ServerVariables("SERVER_NAME")%>">
   <PARAM NAME="CONNECT" VALUE="dsn=ADCDemo;UID=ADCDemo;PWD=ADCDemo;">
</OBJECT>


<!-- VBS scripting for composing queries, updating profiles, and retrieving search results. -->

<SCRIPT LANGUAGE="VBScript">

Dim myQuery

Sub Load
   Grid1.CAPTION = "Arcadia Bay Corporate Phone Directory"

   'Initialize data grid with column names only.
   SControl.SQL = "Select FirstName, LastName, Title, Email, Building, Room, Phone from Employee where 2 < 1"
   SControl.Refresh

End Sub

'Implement "Clear" button - clears all of the QBE fields in preparation for a new "Find."

Sub Clear_OnClick
   SFirst.Value=""
   SLast.Value=""
   STitle.Value=""
   SEmail.Value=""
End Sub


'Implement "Find" button - composes a dynamic SQL query to be processed by the database and returns matching records to be bound to the SGrid object.

Sub Find_OnClick

   myQuery = "Select FirstName, LastName, Title, Type, Email, ManagerEmail, Building, Room, Phone from Employee"

   'Check QBE fields and compose a dynamic SQL query.

   IF (SFirst.Value <> "") THEN
      myQuery = myQuery + " where FirstName like '" + SFirst.Value + "%'"
   End IF

   IF (SLast.Value <> "") THEN
      myQuery = myQuery + " where LastName like '" + SLast.Value + "%'"
   End IF

   IF (STitle.Value <> "") THEN
      myQuery = myQuery + " where Title like '" + STitle.Value + "%'"
   End IF

   IF (SEmail.Value <> "") THEN
      myQuery = myQuery + " where Email like '" + SEmail.Value + "%'"
   End IF

   'Set the new query and then refresh the SControl so that the new results are displayed.

   SControl.SQL = myQuery
   SControl.Refresh
   
End Sub

'Navigation subroutines - based on currency changes to RDS.DataControl (SControl).

'Move to the first record in the bound recordset.

Sub First_OnClick
     SControl.Recordset.MoveFirst
End Sub

'Move to the next record from the current position in the bound recordset.

Sub Next_OnClick
   If SControl.Recordset.EOF Then   'cannot move beyond bottom record
      SControl.Recordset.MoveFirst 
      SControl.Recordset.MoveNext
      Exit Sub
   End If   

   SControl.Recordset.MoveNext

End Sub

'Move to the previous record from the current position in the bound recordset.

Sub Prev_OnClick
If SControl.Recordset.BOF Then   'cannot move beyond top record
      SControl.Recordset.MoveLast   'Get out of BOF buffer
      SControl.Recordset.MovePrevious
      Exit Sub
   End If
   SControl.Recordset.MovePrevious
End Sub

'Move to the last record in the bound recordset.

Sub Last_OnClick
     SControl.Recordset.MoveLast
End Sub

'Submit edits made and pull a clean copy of the new data.

Sub Update_OnClick
     SControl.SubmitChanges
   SControl.Refresh    ' A Refresh is not required in ADC 1.5 after a SubmitChanges, but it ensures fresh data.
End Sub

'Cancel edits and restore original values.

Sub Cancel_OnClick
     SControl.CancelUpdate
End Sub

</SCRIPT>

<BR>
<font color = "#400040">This site powered by Microsoft Remote Data Service. </font>
</BODY>
</HTML>