Hello,
Is there a way to insert a record at the top of a disconnected recordset
after it is retrieved from the database?
.
I know I could create a recordset, add the row, retrieve the data from the
DB, then loop through the DB RS and add the records to the RS that is going
to be passed back to the client. I would prefer not to do it this way.
.
Of course, I would like to get all the data in one-shot from the db, but in
this case, I cannot.
Thanks for your time.
Ralph - 06 Aug 2007 18:43 GMT
> Hello,
> Is there a way to insert a record at the top of a disconnected recordset
[quoted text clipped - 7 lines]
> this case, I cannot.
> Thanks for your time.
I'm likely missing something.
What's wrong with adding a record to the discontinued recordset with the
same process that updates the database with an insert statement?
-ralph
JohnnyC - 06 Aug 2007 22:02 GMT
The added record needs to be the first record in the returned recordset.
.
I understand this requirement is nuts. The only way I know how to
accomplish this is the following
1. create a recordset on-the-fly, append fields, etc
2. add record to on-the-fly rs. This would put this record as the first one
in the set.
3. retrieve data from db
4. loop through retrieved rs and add each record to on-the-fly recordset.
5. return on-the-fly rs to the caller.
The alternative :
1. Create a 'sequence' column in the call to the db.
2. When the set comes back, disconnect it from the connection.
3. Add the record to the set with a sequence of 0.
4. sort the recordset.
5. Return the sorted rs back to the caller.
What I really want to do is put a record at bookmark 1 and shift everything
in the rs down by one. I have no idea if this can be done. I couldn't find
any documentation on this, but the guys on this board are sharp, so I though
somebody might have done thisobscure requirement before.
Thanks again.
>> Hello,
>> Is there a way to insert a record at the top of a disconnected recordset
[quoted text clipped - 17 lines]
>
> -ralph
Mark J. McGinty - 17 Aug 2007 23:43 GMT
> Hello,
> Is there a way to insert a record at the top of a disconnected recordset
[quoted text clipped - 8 lines]
> in this case, I cannot.
> Thanks for your time.
This should be do-able at the [persistence provider] XML level. The basic
idea is to locate the inserted row's node via its XPath, and then move that
node to the top of the nodelist. When ADO de-serializes the recordset, the
physical order of the nodelist dictates the physical order of the records in
the recordset.
''''''''''''''''''''''''''
' This code assumes rs is an open, disconnected recordset, and that one,
' and only one record has been inserted since it was opened.
Dim xml As MSXML2.DOMDocument
Dim DataNode As MSXML2.IXMLDOMNode
Dim FirstChildNode As MSXML2.IXMLDOMNode
Dim InsertedNode As MSXML2.IXMLDOMNode
Set xml = New MSXML2.DOMDocument
rs.Save xml, adPersistXML
Set DataNode = xml.selectSingleNode("xml/rs:data")
Set FirstChildNode = DataNode.ChildNodes(0)
Set InsertedNode = DataNode.selectSingleNode("rs:insert")
DataNode.insertBefore DataNode.removeChild(InsertedNode), FirstChildNode
rs.Close
rs.Open xml
''''''''''''''''''''''''''
-Mark