Hello all,

Do you have had the same problem with resynchronising a row in an ADO recordset with SQL Server 2000, especially when your recordset is build from more than one table? Here is how to do it:

Create two stored procedures in SQL Server:
VB Code:
  1. CREATE PROCEDURE pointiest AS
  2. SELECT Orders.*, Customers.CompanyName
  3. FROM Orders INNER JOIN Customers
  4. ON Orders.CustomerID = Customers.CustomerID
and the second:
VB Code:
  1. CREATE PROCEDURE spJoinResync
  2. @OID Int
  3. AS
  4. SELECT Orders.*, Customers.CompanyName
  5. FROM Orders INNER JOIN Customers
  6. ON Orders.CustomerID = Customers.CustomerID
  7. WHERE Orders.OrderID = @OID
Then, have a form with a commandbutton named 'Command1', and paste the following code in your project:
VB Code:
  1. Option Explicit
  2.  
  3. Private Sub Command1_Click()
  4. Dim cn As ADODB.Connection, rs As ADODB.Recordset
  5.   Set cn = New ADODB.Connection
  6.   Set rs = New ADODB.Recordset
  7.   cn.Open "Provider=SQLOLEDB;Server=xxx;uid=sa;pwd=;database=Northwind"
  8.   rs.CursorLocation = adUseClient
  9.   rs.Open "spJoinTest", cn, adOpenStatic, adLockOptimistic, adCmdStoredProc
  10. '  rs.Properties("Unique Table") = "Orders"
  11. '  rs.Properties("Resync Command") = "EXEC spJoinResync ?"
  12.   rs!CustomerID = "ALFKI"
  13.   rs.Update
  14.   rs.Resync adAffectCurrent
  15.   Debug.Print rs!CompanyName
  16.   rs!CustomerID = "WOLZA"
  17.   rs.Update
  18.   rs.Resync adAffectCurrent
  19.   Debug.Print rs!CompanyName
  20.   rs.AddNew
  21.   rs!EmployeeID = 1
  22.   rs!CustomerID = "BLAUS"
  23.   rs.Update
  24.   rs.Resync
  25.   Debug.Print rs!CompanyName
  26.   rs.Close
  27.   cn.Close
  28. End Sub
When running the project you will not see the updates the resync should have done. Uncomment the rs.Properties lines, and you'll see the resync will work correctly. With uncommented lines, the AddNew method can fail.

Enjoy!!!