473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# ASP.NET Relations vs SQL Inner Join

I am writing a tool to interface with a couple of tables in SQL Server 2000.

I usually write my queries with an Inner Join to bring in fields from seperate tables and load that to a DataSet. I'm wondering if this way is more efficient then using a DataSet.Relations.Add approach or a combination of the two.

When should you use an Inner Join over a Relation within a dataset and vice versa?

For example is this possible:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SqlConnection cn = new SqlConnection("Data Source=" + myServerAddress + ";Initial Catalog=" + myDataBase + ";Integrated Security=SSPI");
  3.  
  4. SqlCommand cmdNewRules = new SqlCommand("Select rg.GroupId, rg.RuleGroup, r.RuleID, r.RuleName From RuleGroup rg INNER JOIN Rules r ON rg.GroupID = r.GroupID", cn);
  5.  
  6. //Create the dataset to be populated with both tables in the hiearchy.
  7. DataSet dsRule = new DataSet();
  8.  
  9. SqlDataAdapter adpRules = new SqlDataAdapter(cmdNewRules);
  10. //Here I don't really want to Fill the dataset twice nor do I need to. 
  11. //But I don't know how to create a DataTable object from a DataSet 
  12. //when the DataSet has been populated by a query using an Inner Join
  13. adpRules.Fill(dsRule,"Rules");
  14. adpRules.Fill(dsRule,"RuleGroup");
  15.  
  16.  

I always see only this example and if I am querying two tables and have the ability to join them at the database level why wouldn't I just do it there?

Expand|Select|Wrap|Line Numbers
  1. //Create connection and sql commands.
  2. SqlConnection cn = new SqlConnection("Data Source=" + myServerAddress + ";Initial Catalog=" + myDataBase + ";Integrated Security=SSPI");
  3. SqlCommand cmdRules = new SqlCommand("Select RuleID, RuleName, GroupID From Rules", cn);
  4. SqlCommand cmdRuleGroup = new SqlCommand("Select GroupId, RuleGroup From RuleGroup", cn);
  5.  
  6. //Create the dataset to be populated with both tables in the hiearchy.
  7. DataSet dsRule = new DataSet();
  8. SqlDataAdapter adpRules = new SqlDataAdapter(cmdRules);
  9. SqlDataAdapter adpRuleGroup = new SqlDataAdapter(cmdRuleGroup);
  10.  
Dec 28 '07 #1
0 2304

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
1
by: ViperDK \(Daniel K.\) | last post by:
i've a database where relations are hold in a special way which the project leaders think of as "performant and uncomplicated" but which is very questionable to me:...
8
by: mesut | last post by:
Mybe it's a stupid question but : I'm starting to learn VB.NET. I have some basic skills. I'm from Mainframe world and I have same question to make my DATABASES (tables and relation) I would like...
3
by: Joe | last post by:
Hi I have a dataset with 2 tables and Relations What is the best way to flatten the 2 files to a new table or xml or file I can loop thru table1 and get the childrows or I can do an Xpath on...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
14
by: kjewell23 | last post by:
Hi. I have the code working just fine except all the data isn't coming up with the ds.relations code. Could you see what I'm doing wrong or what else I need to add. Code down below Dim adapter As...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.