Solved

Merge two recordset objects

Posted on 1998-12-02
5
1,760 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now