Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Additive queries using Recordset?


Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2003, 05:15 PM
TiKiMoN's Avatar
TiKiMoN TiKiMoN is offline
Centurion
 
Join Date: Nov 2002
Location: Clemson, SC USA
Posts: 130
Question Additive queries using Recordset?


I must be having a brain freeze or something... I can't seem to work this out.

The problem I am having is that I have a database I use as the Connection for an ADODB Recordset to perform a query. The database (MS Access database) is read-only when I open it. (I do not want to modify it at all.) Now, I need to perform several queries on the tables in this database to arrive at the final result. My question is, how can I do this without storing temporary tables in the database? I would like to use multiple Recordset variables to achieve the desired query and then dispose of them at the end of the Sub, but I can't think whether or not it's possible to do that.

One alternative I had was to create a temporary database that I COULD write to, and then use loops to dump Recordsets into tables in the new database, until the final table was acqured. This seems a little inefficient though, so I was hoping someone else had a better suggestion. Thanks in advance!
Reply With Quote
  #2  
Old 02-27-2003, 05:39 PM
diver diver is offline
Senior Contributor

* Expert *
 
Join Date: Jun 2001
Location: Illinois
Posts: 865
Default

Code:
...I would like to use multiple Recordset variables to achieve the
desired query and then dispose of them at the end of the Sub, 
but I can't think whether or not it's possible to do that.
Yes, that is possible.

diver
__________________
Sometimes I do not get notification of your post from the forum, which causes a delay. I am apologizing in advance!
Reply With Quote
  #3  
Old 03-01-2003, 12:59 PM
TiKiMoN's Avatar
TiKiMoN TiKiMoN is offline
Centurion
 
Join Date: Nov 2002
Location: Clemson, SC USA
Posts: 130
Default

No doubt a veritable fountain of wit.

However, what I was indirectly implying was that I needed to know more "how to do it" rather than "can it be done".

Say I have database "A". I use an ADODB Recordset ("B") to query 2 tables from A to form a resultant set. Now, I want to use another table from A and the results from B and use another Recordset variable ("C") to hold that result. And finally, one more table from A and another Recordset variable ("D") to hold the results of a query betwen A and C.

So... A -> B.
A | B -> C
A | C -> D

D is the final result I want. Now, without temporarily storing the query results into a separate database, how can I accomplish this using only Recordset variables? I tried using just one SQL statement, but it claims there is an "ambiguous join" and cannot complete the query. The final result needs to be stored in a Data control to populate a MSFlexGrid.

Thanks again for all of your help!!
Reply With Quote
  #4  
Old 03-01-2003, 03:20 PM
diver diver is offline
Senior Contributor

* Expert *
 
Join Date: Jun 2001
Location: Illinois
Posts: 865
Default

okay... I see what you are saying.
actually, I've never heard of anyone describing this logic to formulate recordsets. Granted, it can most likely be done, but with a lot of work. Logically, you can accomplish this in a much easier way.

For example, this is really a pseudocode you have explained:

Database: "Northwind"
Recordset1: SELECT straight from the database -ok

Recordset2: SELECT straight from the database, and also include the results from Recordset1.

Recordset3: SELECT straight from the database and also include the results from Recordset2.

Now, in reality, create ONE select statement and return ONE recordset. There are numerous ways to do this. You might want to check out a good SQL Syntax text, especially the UNION key word. Two issues still exist:

1) A Datacontrol or Datagrid accepts one (1) recordset only.
2) A Flexgrid cannot be hooked up to a Datacontrol.
3) You can, however use the Datagrid.

Hope that helps.
diver
__________________
Sometimes I do not get notification of your post from the forum, which causes a delay. I am apologizing in advance!
Reply With Quote
  #5  
Old 03-03-2003, 04:15 PM
TiKiMoN's Avatar
TiKiMoN TiKiMoN is offline
Centurion
 
Join Date: Nov 2002
Location: Clemson, SC USA
Posts: 130
Default

Quote:
Originally Posted by diver
1) A Datacontrol or Datagrid accepts one (1) recordset only.
2) A Flexgrid cannot be hooked up to a Datacontrol.
3) You can, however use the Datagrid.

Hope that helps.
diver

Oops... I meant to say Datagrid, but MSFlexGrid came out. That is what I am using, so sorry for the confusion on that.

I guess I'll try using a union, but this is going to be one incredibly long SQL statement, provided it works. I will let you know the outcome here. Thanks again!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->