Solved

Get Related Results From A DataSet Automatically

Posted on 2013-06-14
6
119 Views
Last Modified: 2015-01-18
Is there a way to get the "recursive" results from a DataSet object in C# without having to call multiple queries?

I am trying to get a DataSet to act like Entity since, at this point, I cannot use Entity framework.

I have 2 tables in a database that are not linked with foreign keys.  When I add them to my dataset designer, I make the link there.

When I run a query on the first table, I would like it to also return all results from the second table without having to run separate queries for the second table.

Is this possible?  The issue I am having is, I have a DB with no foreign keys and I cannot change it in any way to use Entity.

See my other question related to this one: http://www.experts-exchange.com/Programming/Languages/.NET/Q_28157518.html
0
Comment
Question by:cefranklin
6 Comments
 
LVL 23

Expert Comment

by:nemws1
Comment Utility
When you say they're not linked with foreign keys, you mean they *do* have a common key, so you can relate the tables together, its just that they don't have the foreign key constraint set on tables, right?

Can you just modify your first query so that it is joined with second table right away?
0
 
LVL 2

Author Comment

by:cefranklin
Comment Utility
Sorry for taking so long to respond, swamped right now.

Yes, the 2 tables have a field to relate the two but, in the db the relation is not set, so, when I add the tables to the data designer, I have to make the association myself.

This works as far as, I can run a query and get results for table 1 but, I'd have to run a second query to get any results from table 2.

Is there a way that, when I just run the query on table 1, it will automatically get related entries on the second table via the association that I had to make?
0
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
Comment Utility
Hi,

Apart from joins, i think there is no way to do it!

http://www.aspdotnet-suresh.com/2012/10/how-to-retrieve-data-from-multiple.html

Hope it helps u...
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
Why not simply create a VIEW?

If you have a SQL query that is providing the wanted results, take that query and add 'CREATE VIEW' syntax at the top - run that, and bingo you have your automatic results.

i.e. your C# code now calls the view, not the source tables.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

771 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

10 Experts available now in Live!

Get 1:1 Help Now