Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:21:31+00:00 2026-05-26T06:21:31+00:00

I am wondering how I could collect data from multiple tables most deftly with

  • 0

I am wondering how I could collect data from multiple tables most deftly with C#.
I am not very used to C# and database management: I heard about ADO.NET and LINQ and the simplicity of working with tables, but I didn’t had the time to read about it, yet.

So my approach collecting data is badly complicated:

        int id = 43;
        var collectedData = new System.Collections.Generic.Dictionary<string, string>(); // this will later be all my collected data

        // Load from first table
        string select1 = "SELECT * FROM table1 WHERE ID = " + id;
        DataRow dataRow1= SqlHelper.Execute.SingleRow(select1); // my helperclass returning one single data row of a table
        collectedData["Surname"] = dataRow1["Surname"];
        collectedData["Name"] = dataRow1["Name"];
        collectedData["Age"] = dataRow1["Age"];

        // Load from second table
        string select2 = "SELECT * FROM table2 WHERE ID = " + id;
        DataRow dataRow2= SqlHelper.Execute.SingleRow(select2); 
        collectedData["Mother"] = dataRow2["Mother"];
        collectedData["Father"] = dataRow2["Father"];
        collectedData["Job"] = dataRow2["Job"];

        // ...

So how would you C# and .NET pros solve this? I am looking forward to your code samples!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:21:31+00:00Added an answer on May 26, 2026 at 6:21 am

    If you are working with SQL Server, ADO.NET + LINQ-to-SQL is definitely the way to go.

    Reasons for LINQ:

    1. It fits naturally with your .NET code, IDE, and debugger
    2. You don’t have to maintain your code in one place and your queries in another
    3. You aren’t hard-coding SQL queries and you don’t have to go to the trouble of creating paramterized SQL (which is really a pain in my opinion)
    4. It is super fast to write and surprisingly flexible
    5. Your code will be cleaner and smaller because you don’t have to have ADO.NET and database plumbing everywhere – LINQ takes care of all the hard stuff
    6. You get a nice entity designer that allows you to drag-n-drop from a SQL connection

    Reasons Not to Use LINQ:

    1. If you have to squeeze every last ounce of performance out of a query, LINQ may not be the most natural choice because SQL can sometimes be more flexible. But you should really consider your query carefully to see if there is an easier way to do it.
    2. Some places don’t like the security implications because the tables have to be public to your connected user. Some companies only allow access to tables via SPROCs.

    For your example, you’ll want to create classes (POCO’s) that represent your database entities. Then you’ll use LINQ to query your tables and load data into the new entity objects. I prefer to have a constructor on my domain/entity objects that transform the persistent database objects generated by LINQ into domain-layer objects to be used by the client.

    public class Person
    {
        public int ID { get; set; }
        public string Surname { get; set; }
        public string Name { get; set; }
        public short Age { get; set; }
    
        public Person()
        {
        }
    
        public Person( Persistence.Person src )
        {
          this.ID = src.ID;
          this.Surname = src.surname;
          this.Name = src.name;
          this.Age = src.age;
        }
    }
    
    ...
    public List<Domain.Person> LoadPeople()
    {
        using( var context = this.CreateContext() )
        {
            var personQuery = from p in context.Persons
                              select new Domain.Person( p );
    
            return personQuery.ToList();
        }
    }
    
    public Person LoadPerson( int personID )
    {
        using( var context = this.CreateContext() )
        {
            var personQuery = from p in context.Persons
                              where p.id == personID
                              select new Domain.Person( p );
    
            return personQuery.SingleOrDefault();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was wondering how could i display 'player' sprite from Player.cs class. So far
Hi I was wondering I could make my flash program take input from an
I was wondering what could be the point in trying to delete committed changelists,
I was wondering how could I reload any website using javascript and set it
I've got an issue that was wondering if could be solved in a particular
Wondering if I could get some advice and direction on this following requirement: Need
just wondering if anyone could suggest why I might be getting an error? I'm
Im wondering how i could add a success or fail message to return at
Just wondering if you could help wanting to produce an activity stream in Java,
I was wondering if anyone could point to an Open Source date utility class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.