home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / rds.cab / adctovb.asp < prev    next >
Text File  |  1997-08-14  |  6KB  |  231 lines

  1. <HTML>
  2. <HEAD>
  3. <TITLE> Manually Getting Data through a Custom Business Object </TITLE>
  4. </HEAD>
  5.  
  6. <BODY BACKGROUND="/MSADC/Samples/Addressbook/Arcadia.gif">
  7.  
  8. <CENTER><H1> Manually Getting Data through <BR> a Custom Business Object </H1></CENTER>
  9.  
  10. <!--
  11.     Purpose:     To demonstrate using a custom business object
  12.     Written By:  Microsoft Data Access Group, Microsoft Corporation
  13.     Date:        April, 1997
  14. -->
  15.  
  16. <CENTER>
  17. <Table Border=1><TR><TD ALIGN=CENTER ><FONT SIZE=2 Color="#008080">
  18. <B>UnBound TextBox<B></TD><TD ALIGN=CENTER ><FONT SIZE=2 Color="#008080">
  19. <B>Bound Data Grid</B></TD><TR><TD>
  20.  
  21. <!-- 
  22.     This is included as an example of how you can use data 
  23.     with and unbound control.  If you have the extension FM20.DLL
  24.     on your client machine you can uncomment the associated code.
  25. -->
  26. <!-- Unbound List Box within FM20.DLL, ID=List1 -->
  27. <!--
  28. <OBJECT CLASSID="CLSID:8BD21D20-EC42-11CE-9E0D-00AA006002F3"
  29.     ID="List1"
  30.     WIDTH=108 HEIGHT=100>
  31. </OBJECT>
  32. -->
  33.  
  34. <TD>
  35.  
  36. <!--  Sheridan DataBound Grid Control, ID=GRID -->
  37.  
  38. <Object CLASSID="clsid:AC05DC80-7DF1-11d0-839E-00A024A94B3A"
  39.     CODEBASE="http://<%=Request.ServerVariables("SERVER_NAME")%>/MSADC/Samples/ssdatb32.cab"
  40.     ID=GRID
  41.     datasrc=#ADC
  42.         WIDTH=550 HEIGHT=100>
  43.     <PARAM NAME="AllowAddNew"   VALUE="TRUE">
  44.     <PARAM NAME="AllowDelete"   VALUE="TRUE">
  45.     <PARAM NAME="AllowUpdate"   VALUE="TRUE">
  46.     <PARAM NAME="BackColor"     VALUE="-2147483643">
  47.     <PARAM NAME="BackColorOdd"  VALUE="-2147483643">
  48.     <PARAM NAME="ForeColorEven" VALUE="0">
  49. </OBJECT>
  50.  
  51. </Table>
  52.  
  53. <!--  RDS.DataSpace object, ID=ADS  -->
  54. <OBJECT CLASSID="CLSID:BD96C556-65A3-11D0-983A-00C04FC29E36"
  55.     ID="ADS"
  56.     WIDTH=1 HEIGHT=1>
  57. </OBJECT>
  58.  
  59. <!-- RDS.DataControl object, ID=ADC  -->
  60. <OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
  61.         ID="ADC"
  62.     HEIGHT=1 WIDTH = 1>
  63. </OBJECT>
  64.  
  65. <!-- Input Information Area -->
  66. <TABLE BORDER=1>
  67.     <TR><TD WIDTH=150><FONT SIZE=2 Color="#008080"><B>Server:</B> 
  68.     <TD><INPUT SIZE=70 NAME="Server"> 
  69.  
  70.      <TR><TD WIDTH=150><FONT SIZE=2 Color="#008080"><B>Connection:</B>
  71.        <TD><INPUT SIZE=70 NAME="Connect"> 
  72.                                                        
  73.        <TR><TD WIDTH=150><FONT SIZE=2 Color="#008080"><B>Query:</B>
  74.        <TD><INPUT SIZE=70 NAME="Query">                                           
  75. </TABLE>
  76. <HR>
  77.  
  78. <!-- Buttons to select data source and populate visible data controls -->
  79.  
  80. <INPUT TYPE=BUTTON NAME="BusObjTest" VALUE="Test Business Object">
  81. <INPUT TYPE=BUTTON NAME="Run" VALUE="Run">
  82. <INPUT TYPE=BUTTON NAME="AccessQuery" VALUE="Fill Access Query Info">
  83. <INPUT TYPE=BUTTON NAME="SQLQuery" VALUE="Fill SQL Server Query Info">
  84. </Table>
  85.  
  86. <!-- Buttons for Navigation in data grid  -->
  87. <HR>
  88. <INPUT TYPE=BUTTON NAME="MoveFirst" VALUE="First">
  89. <INPUT TYPE=BUTTON NAME="MovePrev" VALUE="Previous">
  90. <INPUT TYPE=BUTTON NAME="MoveNext" VALUE="Next">
  91. <INPUT TYPE=BUTTON NAME="MoveLast" VALUE="Last">
  92. <INPUT TYPE=BUTTON NAME="Submit" VALUE="Submit Changes">
  93. <INPUT TYPE=BUTTON NAME="Cancel" VALUE="Cancel Changes">
  94. </CENTER><P>
  95.  
  96.  
  97. <SCRIPT LANGUAGE="VBScript">
  98. Option Explicit
  99. '---- enum Values ----
  100. Const adcExecSync = 1
  101. Const adcExecAsync = 2
  102.  
  103. '---- enum Values ----
  104. Const adcFetchUpFront = 1
  105. Const adcFetchBackground = 2
  106. Const adcFetchAsync = 3
  107.  
  108. Dim BObj
  109. Dim ADOR
  110.  
  111. Sub Window_OnLoad
  112.     'Change the asynchronous options such that execution is synchronous
  113.     'and Fetching can occur in the background
  114.     ADC.ExecuteOptions = adcExecSync
  115.     ADC.FetchOptions = adcFetchBackground
  116.  
  117.     'Populate Data Source and Query text boxes with initial data.
  118.     Server.Value = "http://<%=Request.ServerVariables("SERVER_NAME")%>"
  119.         Connect.Value = "DSN=AdvWorks"
  120.      Query.Value = "Select * from Products"
  121.  
  122.     'Use CreateObject method of ADS to load custom business object
  123.     Set BObj = ADS.CreateObject("VbBusObj.VbBusObjCls", Server.Value)
  124. End Sub
  125.  
  126. Sub BusObjTest_OnClick
  127.     'Uses function in custom business object for self-test                               
  128.       MsgBox BObj.Test()
  129. End Sub
  130.  
  131. 'Populate Query box with Microsoft Access Query.
  132. Sub AccessQuery_OnClick
  133.     Connect.Value = "DSN=AdvWorks"
  134.     Query.Value = "Select * from Products"    
  135. End Sub
  136.  
  137. 'Populate Query box with SQL Server Query.
  138. Sub SQLQuery_OnClick
  139.       Connect.Value = "DSN=Pubs;UID=SA;PWD=;"
  140.       Query.Value = "Select * from Authors"
  141. End Sub
  142.  
  143. 'Get data and populate controls
  144. Sub Run_OnClick
  145.     'Get the Recordset
  146.       Set ADOR = BObj.GetRecordset(Connect.Value,Query.Value)
  147.  
  148.     'Populate UnBound List Box
  149.     ' The following code could be uncommented if you have FM20.DLL
  150.     'List1.Clear        'Clear the list box.
  151.     'While Not ADOR.EOF
  152.       '  List1.AddItem ADOR(0).Value
  153.     '  ADOR.MoveNext
  154.     'WEnd
  155.  
  156.     'Populate Bound Data Grid by assigning recordset to the ADC
  157.     Set ADC.SourceRecordset = ADOR
  158.     
  159.     'Optional command specific to the Sheridan Grid to ensure display of the correct data
  160.     Grid.Rebind
  161.  
  162. End Sub
  163.  
  164. 'Change active Record
  165. Sub MoveFirst_OnClick
  166.     ADC.Recordset.MoveFirst
  167. End Sub
  168.  
  169. SUB MoveNext_OnClick
  170.     On Error Resume Next
  171.     ADC.Recordset.MoveNext
  172.     IF ERR.Number <> 0 THEN
  173.         ADC.Recordset.MoveLast  'If already at end of recordset stay at end.
  174.     END IF
  175. END SUB
  176.  
  177. SUB MovePrev_OnClick
  178.     On Error Resume Next
  179.     ADC.Recordset.MovePrevious
  180.     IF ERR.Number <> 0 THEN
  181.         ADC.Recordset.MoveFirst  'If already at start of recordset stay at top.
  182.     END IF
  183. END SUB
  184.  
  185. Sub MoveLast_OnClick
  186.     ADC.Recordset.MoveLast
  187. End Sub
  188.  
  189. SUB Submit_OnClick
  190.     'Set properties on the ADC
  191.     ADC.SERVER = Server.Value
  192.     ADC.CONNECT = Connect.Value 
  193.     ADC.SQL = Query.Value
  194.     
  195.     'Send changes to data source via the ADC
  196.     ADC.SubmitChanges
  197.  
  198.     'Pull fresh data
  199.     ADC.Refresh
  200.     
  201.     'Optional command specific to the Sheridan Grid to ensure display of the correct data
  202.     Grid.Rebind
  203.  
  204. End Sub
  205.  
  206. SUB Cancel_OnClick
  207.     'Set properties on the ADC
  208.     ADC.SERVER = Server.Value
  209.     ADC.CONNECT = Connect.Value 
  210.     ADC.SQL = Query.Value
  211.     
  212.     'Cancel the changes made to the data and resore
  213.     ADC.CancelUpdate
  214.     'Pull fresh data
  215.     ADC.Refresh
  216.  
  217.     'Optional command specific to the Sheridan Grid to ensure display of the correct data
  218.     Grid.Rebind
  219. End Sub
  220.  
  221.  
  222. </SCRIPT>
  223.  
  224. <!-- Link to View Source -->
  225.  
  226. <TABLE BORDER=3><TR><TD><!--#include file="srcform.inc"--></TABLE>
  227. <Center>This site powered by the Microsoft Data Access Components.</Center>
  228.  
  229. </BODY>
  230. </HTML>
  231.