Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ADO.NET Dataset joint query

Posted on 2002-06-13
6
Medium Priority
?
238 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

688 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