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 8423583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:45:43+00:00 2026-06-10T03:45:43+00:00

Hello I have 2 SQL tables that I would like to merge to view

  • 0

Hello I have 2 SQL tables that I would like to merge to view both simultaneously in a datagridview. I can already set this up to view one, via binding it to a dataset, but how can I merge these two based off of a common ID number (for example) that both tables contain?

Current datagridview populate code (the function is fed an empty, new DataTable):

public void populateSingleDataGridView(DataTable dt,  DataGridView dg, string SN_DB_Name)
{
     string selectProgramString = "select * from " + SN_DB_Name;
     SqlDataAdapter sqlDataAdaptor = new SqlDataAdapter(selectProgramString,connectionString);
     dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
     sqlDataAdaptor.Fill(dt);
     dg.DataSource = dt;
}
  • 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-06-10T03:45:44+00:00Added an answer on June 10, 2026 at 3:45 am

    You can join two tables together:

    select table1.Field1 as GridColumn1, table2.Field2 as GridColumn2
    from table1
        inner join table2
        on table1.CommonId = table2.CommonId
    

    If you want to keep your current code as is, then one option is to create a view, e.g.

    create view GridData
    as
        select table1.Field1 as GridColumn1, table2.Field2 as GridColumn2
        from table1
            inner join table2
            on table1.CommonId = table2.CommonId
    

    Then you can pass view name into SN_DB_Name.

    Note: This option will force you to create views for any queries with joins. IMHO a better option would be to pass an entire sql string.

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello I have a datatable that I would like to filter with a single
I encountered SQL queries that looked like select hello from foo.bar I found that
Hello everybody Well my question is about sql commands... If I have 2 tables
Hello I have two mysql tables one that holds username and password second that
Hello I have a project that is linked to a SQL Compact database (xxx.sdf
Hello I have a very large SQL script and while trying to execute it
hello I have my code that connects to my ftp server $conn_id = ftp_connect($ftp_server);
Hello I have 2 tables: Events (idEvent, eventName) and Registrations(idRegistration, idEvent, idPerson) People register
I would like to create an array (in php) from sql results like this:

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.