gridview繫結兩個或多個數據源
阿新 • • 發佈:2019-02-09
遇到了一個gridview需要繫結同一個資料庫裡幾張表的資料的問題。
基本思路如下:
select * from 表一,表二 where 表一.id=表二.id
這是兩張表的情況。
直接上程式碼:
<pre name="code" class="sql">string sqlstr = "select android.product_test_id ,android.experiment_id, android.android_staff, android.android_date,"+ "third_experiment.experiment_id,third_experiment.experiment_name,"+ "third_product_test.project_name,third_product_test.factory_name,third_product_test.product_type,third_product_test.sampl_batch " +"from android, third_experiment, third_product_test where android.product_test_id=third_product_test.product_test_id and android.experiment_id=third_experiment.experiment_id";
<pre name="code" class="sql">android,<pre name="code" class="html"><pre name="code" class="sql">third_experiment
<pre name="code" class="sql">third_product_test
是資料庫名
其他的是欄位名稱
根據後面的級聯匹配,可以正確的取出所需要的欄位,並且繫結到gridview的列上。