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

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