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;
}
You can join two tables together:
If you want to keep your current code as is, then one option is to create a view, e.g.
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