[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

ADO.NET Dataset joint query

Posted on 2002-06-13
6
Medium Priority
?
243 Views
Last Modified: 2011-10-03
I have two tables tb1, tb2 in one dataset ds
tb1 has id, name
tb2 has tb1_id, description, price

I want a query or a way to display as this:
id1, name, description, price
id2, name, description, price

I know this can be done easily write a query deritely from
database: Select .... from tb1, tb2 Where tb1.id=tb2.tb1_id

But, these two tables are in the Dataset now, and I want to get the same result like the query does? (from Dataset not from database directly)

0
Comment
Question by:GoodJun
  • 3
  • 2
6 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 7077203
1. Look for a matched-merge algorithm example.
2. You can implement a lookup algorithm, but that usually isn't as fast as the merge (1).
3. Which ever algorithm you choose, drive the process from the smaller recordset (if they aren't the same size).

==========================================
For (1), you will need to sort both tables in ID order.
For (1), you should set a bookmark and return to it when you start a new ID, if there are multiple matching rows for your ID values.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 7077464
I would like to note this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconIntroductionToDatasetRelations.asp

In fact, using the DataRelation Object, you can use some functions like GetParents and GetChilds to retrieve the related records.
Note that you won't get 1 "recordset" will the data as you requested, but will scan throug one table and GetChilds for each row etc...

CHeers

0
 
LVL 10

Author Comment

by:GoodJun
ID: 7092512
Thanks for the comments. I will do some test use both of your suggestions and get back to you.

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 10

Author Comment

by:GoodJun
ID: 7093769
aikimark,
Through some reading with Dataset, I wonder if it is suitable for my case to use the merge method. My two tables are in the same dataset, and different name, the schema is totally different (except one column). Can you
shed some lights or give a simple example?

Thanks,
0
 
LVL 46

Expert Comment

by:aikimark
ID: 7094653
if you have a many-to-one relationship between tables, you will need two recordsets in ID order.  If your recordsets aren't already in this order, try something like:
rs2original.sort "ID"
set rs2sorted = rs2original.openrecordset()

=============================================
synchronize the second recordset as you move through the first recordset.

rs1.movefirst
Do Until rs1.EOF
   rs2sorted.finfirst "ID=" & rs1.fields("ID")
   'place your processing code here

   rs1.movenext
Loop
0
 
LVL 10

Author Comment

by:GoodJun
ID: 7105468
aikimark,
I have created a 50pts question for you to chek out
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

640 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