PRB: Records Are Not Added When addRecord and updateRecord Methods Are Used in Same Event (263621)



The information in this article applies to:

  • Microsoft Visual InterDev 6.0

This article was previously published under Q263621

SYMPTOMS

If the addRecord() and updateRecord() methods of a Recordset Design-Time Control (DTC) are used in the same event (for example, button_onclick), you may find that the new record is not added or that unexpected results occur.

CAUSE

Both of these methods require a round-trip from the client to the server. However, only one trip to the server can occur from an event. The problem behavior occurs because there is an attempt to make two trips to the server from the same event.

RESOLUTION

There are two ways to work around this problem:
  • Use two different events, one for each method. For example, use two buttons (btnAdd and btnSave) and place the addRecord() method in the btnAdd_onclick() event and the updateRecord() method in the btnSave_onclick() event.
  • If you need to add a record from within the same event, use the addImmediate() method of Recordset DTC in place of the addRecord() method.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Add an Active Server Pages (ASP) page to the project.
  2. Add a Recordset DTC. Enable Scripting Object Model when you are prompted to do so.
  3. Add a Button DTC, and rename it btnOneEventAdd.
  4. Open the Script Outline window (from the View menu, select Other windows, and then select Script Outline).
  5. Locate and expand the btnOneEventAdd object (expand Server Objects & Events), and double-click onclick event.
  6. Place the following code in the generated onclick event:
    Sub btnOneEventAdd_onclick()
      Recordset1.addRecord
      Recordset1.fields.setValue "value", "123"
      Recordset1.updateRecord
    End Sub
    					
  7. View the page in the browser and check the results in the database.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

190768 BUG: Error Calling Some Methods from OnDatasetComplete

190591 BUG: Inserting a New Record With addImmediate May Fail


Modification Type:MajorLast Reviewed:4/21/2001
Keywords:kbCtrl kbprb KB263621