我有兩個表,table1
和table2
。我想從table2
從table1
和column1
檢索column1
。然後結合這兩個結果並作爲單獨的列在網格視圖中顯示。這裏是我的代碼:合併來自mysql中兩個數據集的結果
string query4 = "select tablename from table1 where tid='1'";
MySqlCommand command4 = new MySqlCommand(query4, connection);
DataSet ds = new DataSet();
adapter.SelectCommand = command4;
adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
string query5 = "select fname from table2 where id='1'";
MysqlCommand command5 = new MySqlCommand(query5, connection);
DataSet ds2 = new DataSet();
adapter.SelectCommand = command5;
adapter.fill(ds2);
Gridview1.DataSource = ds;
這給了我只有table1
價值,但我想在單個網格視圖中顯示來自table1
和table2
兩列。
你的意思行或列一個
DataSet
?以下只有UNION響應與將它們作爲2行和1列返回有關。我的回覆(JOIN)涉及讓他們返回爲1行,2列。我不確定凱文的答案會給你什麼 –