Solved

Merge two recordset objects

Posted on 1998-12-02
5
1,852 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

617 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