Solved

Get Related Results From A DataSet Automatically

Posted on 2013-06-14
6
120 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
ID: 39247945
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
ID: 39266474
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
ID: 39304760
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
ID: 39304881
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

920 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

11 Experts available now in Live!

Get 1:1 Help Now