Another way to get data into a web page: using OleDB or ODBC

Here’s a way to get data into a web page to be viewed by a web browser.

The code first spits out some text into a variable, then writes the variable to a file in the c:\Inetpub\WWWRoot folder. If you have Internet Information Server installed (on WinXP Pro choose Control Panel- Add/remove programs->Add/Remove Windows Components) then you can see the file by navigating to http://localhost/t.asp

The sample uses ADO and either the VFPOleDB provider or the very old VFP ODBC driver (remember that?) to access VFP sample data from within an HTM page.

Because this uses VBScript to access the data on the web page, the execution time is when the page gets rendered, and the data lives on the client machine.

Also, you can experiment with debugging scripts by unchecking Tools->Options->Advanced->Disable Script Debugging. This will allow you to use a script debugger such as VS to set breakpoints in your code.

TEXT TO MyVar TEXTMERGE

          <HTML>

          <BODY>

          <%

                   response.write("This is server side code.")

                   IF request.Form("Cust_id").Count > 0 then

                             response.write("Current Customer = " & request.Form("Cust_id").item(1))

                   END IF

                   response.write("<p>")

          %>

          <object id=ADOConn classid=CLSID:00000514-0000-0010-8000-00AA006D2EA4></object>

          <script Language=VBScript>

                   fUseODBC =true

                   document.write("This code executes on client side (within the process of the browser) <<TRANSFORM(DATETIME())>> <p>")

                  

                   IF fUseODBC then

                             document.write("Using ODBC <<TRANSFORM(DATETIME())>>" )

                             ADOConn.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=<<HOME()>>samples\data\testdata.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO"

                   ELSE

                             document.write("Using OleDB <<TRANSFORM(DATETIME())>>")

                             ADOConn.Open "Provider=VFPOLEDB.1;Data Source=<<HOME()>>samples\data\testdata.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO"

                   END If

                   Set rs = ADOConn.Execute("SELECT company,cust_id FROM customer")

                   document.write("<form method=post action=t.asp>")

                   document.write("<p>Company: <select name=Cust_id>")

                   rs.MoveFirst

                   Do while Not rs.EOF

                             company=rs.Fields(0)

                             cust_id = rs.Fields(1)

                            

                             document.write("<option value=" & cust_id & ">" & company)

                             document.write("</option>")

                             rs.MoveNext

                   Loop

                   rs.Close

                   ADOConn.Close

                   document.write("</select><p>")

                   document.write("<input type=submit value=Doit />")

                   document.write("</form>")

          </script>

          </form>

          </BODY>

          </HTML>

ENDTEXT

STRTOFILE(MyVar,"c:\inetpub\wwwroot\t.asp")

RETURN

*IF you want to run it automatically (however, the security warnings will abound):

oIE=CREATEOBJECT("internetexplorer.application")

oIE.Visible=1

oIE.Navigate("c:\t.htm")

RETURN