Solved

ADO.NET Dataset joint query

Posted on 2002-06-13
6
230 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
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 142

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 45

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 82
maro to copy and paste from one worksheet to another based on a condition 11 53
Access 2013 combo box not working 3 44
Help me. 3 54
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

773 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