Solved

ADO.NET Dataset joint query

Posted on 2002-06-13
6
237 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 100 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
Technology Partners: 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month9 days, 14 hours left to enroll

623 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