?
Solved

Get Related Results From A DataSet Automatically

Posted on 2013-06-14
6
Medium Priority
?
126 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
4 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

850 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