I have a database with two tables. Both of these tables are related and have the same key field. For example, both of them have data rows corresponding to ISBN = 12345, but the two tables have different data about this ISBN.
So, I am trying to figure out how to display data from both tables into a single dataGridView. I tried some SQL commands that I found on the Internet, but it looks like C # commands may be different from regular SQL queries.
Suppose that table 1 has the following fields: ISBN, color, size, and table2 have the fields ISBN, weight.
I need a way to display ISBN, color, size and weight in a datagrid view. I think I will have to somehow do this with the adapter. I can connect and make queries in tables separately and show this data in my datagridview, but I cannot figure out how to mix data from two separate tables.
If you have a good resource, I can read about it, I would like to receive it, my google-fu fails.
Here is an example of what I can do now with my database:
private void Form1_Load(object sender, EventArgs e)
{
this.bookTableAdapter.Fill(this.database1DataSet.Book);
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + @"C:\Users\Geoff\Documents\cs 351\Database1.accdb" + ";Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(connectionString);
string query = "select * from Book where ISBN = 12345";
OleDbCommand com = conn.CreateCommand();
com.CommandText = query;
OleDbDataAdapter adapter = new OleDbDataAdapter(com);
DataSet data = new DataSet();
conn.Open();
adapter.Fill(data);
conn.Close();
dataGridView1.DataSource = data.Tables[0];
}
So, essentially, I would like to do what I did above, but I want to also include data from another table. Another table also has an ISBN key field and contains ISBN values that correspond to the first table.