SubmitChanges Method Example (VBScript)

Microsoft ActiveX Data Objects (ADO)

SubmitChanges Method Example (VBScript)

The following code fragment shows how to use the SubmitChanges method with an RDS.DataControl object.

To test this example, cut and paste this code into a normal ASP document and name it SubmitChanges.asp. ASP script will identify your server.

<%@ Language=VBScript %>
<HTML>
<BODY>
<H2>RDS API Code Examples</H2>
<H3>Remote Data Service SubmitChanges and CancelUpdate Methods</H3>

<!-- RDS.DataControl with parameters set at design time -->
<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
    ID=RDC HEIGHT=1 WIDTH=1>
    <PARAM NAME="SQL" VALUE="Select * from Employee for browse">
    <PARAM NAME="SERVER" VALUE="http://<%=Request.ServerVariables("SERVER_NAME")%>">
    <PARAM NAME="CONNECT" VALUE="Provider=SQLOLEDB;User Id=rdsdemo;Password=rdsdemo;Initial Catalog=AddrBookDB;"> 
</OBJECT>

<TABLE DATASRC="#RDC">
<THEAD>
<TR ID="ColHeaders">
   <TH>ID</TH>
   <TH>FName</TH>
   <TH>LName</TH>
   <TH>Name</TH>
   <TH>Title</TH>
   <TH>Type</TH>
   <TH>Email</TH>
   <TH>MgrEmail</TH>
   <TH>Bldg</TH>
   <TH>Rm</TH>
   <TH>Phone</TH>
</TR>
</THEAD>

<TBODY>
<TR>
   <TD> <INPUT DATAFLD="ID" size=4> </TD>
   <TD> <INPUT DATAFLD="FirstName" size=10> </TD>
   <TD> <INPUT DATAFLD="LastName" size=10> </TD>
   <TD> <INPUT DATAFLD="Name" size=15> </TD>
   <TD> <INPUT DATAFLD="Title" size=20> </TD>
   <TD> <INPUT DATAFLD="Type" size=10> </TD>
   <TD> <INPUT DATAFLD="Email" size=10> </TD>
   <TD> <INPUT DATAFLD="ManagerEmail" size=10> </TD>
   <TD> <INPUT DATAFLD="Building" size=3> </TD>
   <TD> <INPUT DATAFLD="Room" size=5> </TD>
   <TD> <INPUT DATAFLD="Phone" size=8> </TD>
</TR>
</TBODY>
</TABLE>

<HR>
<INPUT TYPE=BUTTON NAME="SubmitChange" VALUE="Submit-Changes">
<INPUT TYPE=BUTTON NAME="CancelChange" VALUE="Cancel-Update"><BR>
<H4>Alter a current entry in the table. Move off that Row. <BR>
Submit the Changes to your DBMS or cancel the updates. </H4>
</Center>
<Script Language="VBScript">
<!--
' Set parameters of RDS.DataControl at Run Time
Sub SubmitChange_OnClick
    RDC.SubmitChanges    
    RDC.Refresh
End Sub

Sub CancelUpdate_OnClick
    RDC.CancelUpdate
    RDC.Refresh
End Sub
-->
</Script>
</BODY>
</HTML>

The following code fragment shows how to use the SubmitChanges method with an RDSServer.DataFactory object. You may want to submit changes to the RDSServer.DataFactory if you are working on a Visual Basic project where the RDS.DataControl isn't used. To create this project, open a Visual Basic form and place on it a list box (List1), two text boxes (txtConnect and txtGetRecordset), and two command buttons (cmdGetRecordset and cmdSubmitChanges).

Dim ads As Object    ' RDS.DataSpace object
Dim adf As Object    ' RDSServer.DataFactory object

Private Sub UserDocument_Initialize()
    Call Form_Load
End Sub

Private Sub Form_Load()
    txtConnect.Text = "Dsn=Pubs;Uid=sa;Pwd=;"
    txtGetRecordset.Text = "Select au_lname from authors"
End Sub

Private Sub cmdGetRecordset_Click()
    Dim Server As String
    Server = txtServer.Text

    ' Create RDS.DataSpace using CreateObject Method of RDS.DataSpace.
    Set ads = CreateObject("RDS.DataSpace")
    Set adf = ads.CreateObject("RDSServer.DataFactory", Server)

    ' Populate ListBox with Recordset.
    MousePointer = vbHourglass
    Dim objADORs As Object
    Set objADORs = adf.Query(CStr(txtConnect.Text), CStr(txtGetRecordset.Text))
    List1.Clear
    While Not objADORs.EOF
        List1.AddItem objADORs(0).Value
        objADORs.MoveNext
    Wend
    MousePointer = vbNormal
End Sub
Sub cmdSubmitChanges_OnClick
    adf.SubmitChanges " Dsn=Pubs;Uid=sa;Pwd=;",_
    objADORs
End Sub