Solved

Merge two recordset objects

Posted on 1998-12-02
5
1,816 Views
Last Modified: 2013-12-25
I have two recordsets objects which are currently open.
One of these has xx no. of dummy fields . I want to add
column values of the other recordset object in these dummy columns for each row. In short i want to merge the result of these two recordset objects
coz i have to send a single VARIANT object back to the client App from my DLL
Here is my sample code which fails for some reason.

'
'Pseudo Code
'col1 is int and col2 is text
'MSSQL server 7.0 ADO 2.0
'
cmd.CommandText = "select col1,col2 from table Sample1"

Dim record As New ADODB.Recordset
record.CursorLocation = adUseClient
record.Open cmd, , adOpenForwardOnly, adLockReadOnly, adCmdText

cmd.CommandText = "select 0,'x', col3, col4 from Sample2"

Dim record1 As New ADODB.Recordset
record1.CursorLocation = adUseClient
record1.Open cmd, , adOpenForwardOnly, adLockReadOnly, adCmdText

if record.GetCount > record1.GetCount Then
      do while not record.EOF
            record1.Fields(0).Value = record.Fields(0).Value
            record1.Fields(1).Value = record.Fields(1).Value            
            record.MoveNext
            record1.MoveNext
      loop
else
'
'
End if
0
Comment
Question by:vdv
5 Comments
 
LVL 1

Expert Comment

by:Staplehead
ID: 1497928
why can't you just union the two samples together in one recordset?

larry
0
 

Expert Comment

by:chiche
ID: 1497929
I guess Larry meant: join
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1497930
What exactly is going wrong?
0
 
LVL 3

Accepted Solution

by:
cognition earned 100 total points
ID: 1497931
From looking at your code, you only go into the loop if the first recordset has more records than the second, but you continue to do a movenext on the second recordset which will have EOF set to True before EOF is set to True on the first recordset.

if record.GetCount > record1.GetCount Then
    do while not record1.EOF
        record1.Fields(0).Value = record.Fields(0).Value
        record1.Fields(1).Value = record.Fields(1).Value
        record.MoveNext
        record1.MoveNext
    loop
else
    do while not record.EOF
        record1.Fields(0).Value = record.Fields(0).Value
        record1.Fields(1).Value = record.Fields(1).Value
        record.MoveNext
        record1.MoveNext
    loop
End if

Other problems may be that you need to use RecordCount with ADO not GetCount, or that RecordCount will return -1 if it cannot determine the number of rows returned.
0
 

Author Comment

by:vdv
ID: 1497932
I want to merge the results of recordset A into another recordset B after B is opened. I want to know if this possible.

I cannot use composite recordset as i will lose the result of first recordset when i use the nextrecordset command to execute the next query in the commandtext property  

larry could u give more detail about u'r solution
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question