MDAC 2.5 SDK - ADO


 

Step 2: Get the Data

In this step you will write the code to open an ADO Recordset and prepare to send it to the client. Open the file XMLResponse.asp with a text editor, such as Windows Notepad, and insert the following code.

<%@ codepage="65001" %>
<object id="rstCustomers" progid="ADODB.Recordset" runat="Server">
</object>
<!-- metadata name="Microsoft ActiveX Data Objects 2.5 Library" 
     type="TypeLib" uuid="{00000205-0000-0010-8000-00AA006D2EA4}" -->
<%
  Option Explicit
  Response.Buffer = True

  Dim strSQL, strConnection

  Response.ContentType = "text/xml"
  Response.Expires = 0
  Response.Buffer = False

  strSQL="SELECT title_id, title, type FROM titles" & _
         " ORDER By title"

  strConnection = "Provider=MSDataShape;Data Provider=SQLOLEDB;" & _
                      "Database=Pubs;Data Source=SRV;User Id=sa;" & _
                        "Password=;"

  rstCustomers.Open strSQL, strConnection, adOpenStatic, 
      adLockBatchOptimistic

Be sure to change the value of the Data Source parameter in strConnection to the name of your Microsoft SQL Server computer. The codepage for the page is set to 65001 (Unicode) so that it will return XML.

Keep the file open, and go on to the next step.

Next   Step3: Send the Data