Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get Related Results From A DataSet Automatically

Posted on 2013-06-14
6
Medium Priority
?
125 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
[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
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 2000 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 49

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

618 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