你的查詢綁定與gridview應該是這樣的。
SELECT Items.ItemId, ItemCatogory.CatogoryName FROM Items JOIN ItemCatogory USING(CatagoryId)
這裏是一個示例代碼來做到這一點:
using System.Data;
using System.Data.SqlClient;
然後
SqlDataAdapter da;
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand();
static SqlConnection oc = new SqlConnection(@"Data Source=xxxx;Network Library=DBMSSOCN;Initial Catalog=xxxx;User Id=xxxx;Password=xxxx;");
cmd.CommandText = "SELECT Items.ItemId, ItemCatogory.CatogoryName FROM Items JOIN ItemCatogory USING(CatagoryId)";
oc.Open();
cmd.Connection = oc;
da = new SqlDataAdapter(cmd);
da.Fill(ds);
cmd.ExecuteNonQuery();
GridView1.DataSource = ds;
GridView1.DataBind();
oc.Close();
Theres很多方式。哪一個你想要Dataset,Linq,entityframework,SqlCommand? – spajce 2013-02-20 14:30:56