Re-saving as XML after adding a new record

Re-saving as XML after adding a new record

Post by kbale » Wed, 17 Sep 2003 01:56:13


I have a disconnected recordset that I am persisting as a local XML
document to help me with some of the UI elements (i.e. dynamic lists,
etc). My problem occurs when I add new records. When I add records, I
send the recordset to an ActiveX DLL, connect it, and call
UpdateBatch. This works fine but I then need to update my XML doc.

I can call adoRS.Save(xmlDoc, adPersistXML) again after the update but
the new record does not get saved when I do this. The record is in the
recordset and it's status is Unmodified (after the update) so I don't
know why it doesn't show up. I've also tried persisting to an external
XML file after the update but it doesn't show up there, either. I've
even tried filtering the recordset down until only the new record is
in it but my rs:data element is empty when I persist it.

I'm using VB6 with ADO 2.7
 
 
 

Re-saving as XML after adding a new record

Post by Val Mazu » Wed, 17 Sep 2003 10:21:07

Hi Kyle,

It should work with Save method fine. What is your code and which version of
ADO are you using

--
Val Mazur
Microsoft MVP
Check Virus Alert, stay updated
http://www.yqcomputer.com/

 
 
 

Re-saving as XML after adding a new record

Post by Kyle Bale » Wed, 17 Sep 2003 23:37:55

his is a multi-part message in MIME format.


Tried to strip my code down to demonstrate the error. What I have isn't EXACTLY the same error but close enough to demonstrate my problem. After Command2_Click executes, the new record is in the XML doc but the ADMIN record is gone (at least, it is for me).

NOTE: When I remove the data binding on the text boxes and manually populate the ALIAS and LastName fields in Command3_Click, it works fine.

Here's the form. The DataMember property for Text1 and Text2 are ALIAS and LastName respectively (using the Employees table from Duwamish).

Dim adoRS As New ADODB.Recordset
Dim xml As New MSXML2.DOMDocument

Private Sub Command3_Click()
adoRS.AddNew
End Sub

Private Sub Command2_Click()
Dim o As New Project2.Class1
o.PutRecordset adoRS
Set o = Nothing
adoRS.MoveFirst
adoRS.Save xml, adPersistXML
End Sub

Private Sub Form_Load()
Dim o As New Project2.Class1

Call o.GetEmployees(adoRS)
Set o = Nothing

adoRS.Save xml, adPersistXML

Set Text2.DataSource = adoRS
Set Text3.DataSource = adoRS
End Sub

Here's the code for the class (in a separate project). Taken, for the most part, from older phases of Duwamish:

Private g_strConnectionString As String

Public Function PutRecordset( ByRef Recordset As ADODB.Recordset) As Boolean

Dim adoConnection As ADODB.Connection

PutRecordset = False

Set adoConnection = New ADODB.Connection
adoConnection.Open g_strConnectionString
Set Recordset.ActiveConnection = adoConnection
Recordset.UpdateBatch
Set Recordset.ActiveConnection = Nothing

adoConnection.Close
Set adoConnection = Nothing

PutRecordset = True

End Function


Public Function GetRecordset( _
ByVal strSQLQuery As String, _
ByRef adoRecordset As ADODB.Recordset) As Boolean


Dim adoConnection As ADODB.Connection

GetRecordset = False

Set adoConnection = New ADODB.Connection
adoConnection.Open g_strConnectionString

Set adoRecordset = New ADODB.Recordset
adoRecordset.CursorLocation = adUseClient
adoRecordset.Open strSQLQuery, adoConnection, adOpenStatic, adLockBatchOptimistic, adCmdText

Set adoRecordset.ActiveConnection = Nothing
adoConnection.Close
Set adoConnection = Nothing

GetRecordset = True

End Function

Public Function GetEmployees(ByRef adoInsrBrnch As ADODB.Recordset) As Boolean

Dim adoRS As ADODB.Recordset

GetInsrBrnchRS = GetRecordset("SELECT * FROM Employees", adoRS)

Set adoInsrBrnch = adoRS
Set adoRS = Nothing

End Function

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1226" name=GENERATOR>
<STYLE></STYLE>
</HEAD><FONT face=Arial><FONT size=2>
<BODY>
<DIV><FONT face=Verdana>Tried to strip my code down to demonstrate the error.
What I have isn't EXACTLY the same error but close enough to demonstrate my
problem. After Command2_Click executes, the new record is in the XML doc
but the ADMIN record is gone (at least, it is for me).</FONT></DIV>
<DIV><FONT face=Verdana><FONT face=Arial></FONT>&n
 
 
 

Re-saving as XML after adding a new record

Post by Val Mazu » Thu, 18 Sep 2003 11:17:24

his is a multi-part message in MIME format.


Hi Kyle,

Since I cannot run your code I will try to make some assumptions. First try to get rid off the situation where you have declaration of ADO -related (and not only) object variables together with instantiation of them. Using of

Dim adoRS As New ADODB.Recordset

is not a good idea, since may lead to some problems with the recordset and memory leaking. You should split it into two statements

Dim adoRS As ADODB.Recordset
Set adoRS = New ADODB.Recordset

You could place Set somewhere in a load of the form. Since problem disappears with removing bound mode, try to check if one record does not replace another one. Check how many rows you had before and after you call AddNew

--
Val Mazur
Microsoft MVP
Check Virus Alert, stay updated
http://www.microsoft.com/security/incident/blast.asp


"Kyle Baley" < XXXX@XXXXX.COM > wrote in message news:u% XXXX@XXXXX.COM ...
Tried to strip my code down to demonstrate the error. What I have isn't EXACTLY the same error but close enough to demonstrate my problem. After Command2_Click executes, the new record is in the XML doc but the ADMIN record is gone (at least, it is for me).

NOTE: When I remove the data binding on the text boxes and manually populate the ALIAS and LastName fields in Command3_Click, it works fine.

Here's the form. The DataMember property for Text1 and Text2 are ALIAS and LastName respectively (using the Employees table from Duwamish).

Dim adoRS As New ADODB.Recordset
Dim xml As New MSXML2.DOMDocument

Private Sub Command3_Click()
adoRS.AddNew
End Sub

Private Sub Command2_Click()
Dim o As New Project2.Class1
o.PutRecordset adoRS
Set o = Nothing
adoRS.MoveFirst
adoRS.Save xml, adPersistXML
End Sub

Private Sub Form_Load()
Dim o As New Project2.Class1

Call o.GetEmployees(adoRS)
Set o = Nothing

adoRS.Save xml, adPersistXML

Set Text2.DataSource = adoRS
Set Text3.DataSource = adoRS
End Sub

Here's the code for the class (in a separate project). Taken, for the most part, from older phases of Duwamish:

Private g_strConnectionString As String

Public Function PutRecordset( ByRef Recordset As ADODB.Recordset) As Boolean

Dim adoConnection As ADODB.Connection

PutRecordset = False

Set adoConnection = New ADODB.Connection
adoConnection.Open g_strConnectionString
Set Recordset.ActiveConnection = adoConnection
Recordset.UpdateBatch
Set Recordset.ActiveConnection = Nothing

adoConnection.Close
Set adoConnection = Nothing

PutRecordset = True

End Function


Public Function GetRecordset( _
ByVal strSQLQuery As String, _
ByRef adoRecordset As ADODB.Recordset) As Boolean


Dim adoConnection As ADODB.Connection

GetRecordset = False

Set adoConnection = New ADODB.Connection
adoConnection.Open g_strConnectionString

Set adoRecordset = New ADODB.Recordset
adoRecordset.CursorLocation = adUseClient
adoRecordset.Open strSQLQuery, adoConnection, adOpenStatic, adLockBatchOptimistic, adCmdText

Set adoRecordset.ActiveConnection = Nothing
adoConnection.Close
Set adoConnection = Nothing

GetRecordset = True

End Fu