Solved

ADO.NET Dataset joint query

Posted on 2002-06-13
6
227 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 45

Expert Comment

by:aikimark
Comment Utility
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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
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
Comment Utility
Thanks for the comments. I will do some test use both of your suggestions and get back to you.

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 10

Author Comment

by:GoodJun
Comment Utility
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 45

Expert Comment

by:aikimark
Comment Utility
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
Comment Utility
aikimark,
I have created a 50pts question for you to chek out
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now