Solved

Get Related Results From A DataSet Automatically

Posted on 2013-06-14
6
123 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 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 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

707 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