ConvertToString Method Example (VBScript)
The following example shows how to convert a Recordset into a MIME-encoded string using the RDSServer.DataFactory ConvertToString method. It then shows how the string can be converted back into a Recordset. Cut and paste the following code to Notepad or another text editor and save it as ConvertToString.htm.
<!-- BeginConvertToStringVBS -->
<HTML>
<HEAD><TITLE>ConvertToString Example</TITLE><HEAD>
<BODY>
<SCRIPT LANGUAGE=VBSCRIPT>
Sub ConvertToStringX()
Dim objRs, objDF, strServer, vString
Const adcExecSync = 1
Const adcFetchUpFront = 1
' Replace value below with your server name to use without ASP.
strServer = "http://<%=Request.ServerVariables("SERVER_NAME")%>">
Set objDF = RDS1.CreateObject("RDSServer.DataFactory", strServer)
Set objRs = objDF.Query(txtConnect.Value,txtQueryRecordset.Value)
' convert Recordset to MIME encoded string
vString = objDF.ConvertToString(objRs)
' display MIME string for demo purposes
txtRS.value = vString
' convert MIME string back to useable ADO Recordset
' using RDS.DataControl
RDC1.SQL = vString
RDC1.ExecuteOptions = adcExecSync
RDC1.FetchOptions = adcFetchUpFront
RDC1.Refresh
MsgBox "RecordCount = " & RDC1.Recordset.RecordCount
End Sub
</SCRIPT>
Connect String:
<INPUT TYPE=Text NAME=txtConnect SIZE=50
VALUE="Provider=sqloledb;Initial Catalog=pubs;Integrated Security='SSPI';">
<BR>
Query:
<INPUT TYPE=Text NAME=txtQueryRecordset SIZE=50
VALUE="select * from authors">
<BR>
<INPUT TYPE=Button VALUE="ConvertToString" OnClick="ConvertToStringX()">
<BR>
MIME Encoded RS: <BR>
<TEXTAREA NAME=txtRS ROWS=15 COLS=50 WRAP=virtual></TEXTAREA>
<!-- RDS.DataSpace ID RDS1 -->
<OBJECT ID="RDS1" WIDTH=1 HEIGHT=1
CLASSID="CLSID:BD96C556-65A3-11D0-983A-00C04FC29E36">
</OBJECT>
<!-- RDS.DataControl ID RDC1 -->
<OBJECT ID="RDC1" WIDTH=1 HEIGHT=1
CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33">
</OBJECT>
</BODY>
</HTML>
<!-- EndConvertToStringVBS -->
See Also
ConvertToString Method (RDS) | Recordset Object