我想從Products
表中獲取產品名稱到CustomerProducts
表。在sql數據庫中加入2個表或外鍵?
Products
表:
customerproducts
表:
UPDATE:
public void bindgrid()
{
SqlConnection conn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True");
SqlCommand cmd = new SqlCommand("select Name From Products p InnerJoin CustomerProducts cp ON(p.ProductID = cp.ProductID)", conn);
SqlDataAdapter da = new SqlDataAdapter("", conn);
da.SelectCommand = new SqlCommand("select ProductName From Products p InnerJoin CustomerProducts cp ON(p.ProductID = cp.ProductID", conn);
DataSet ds = new DataSet();
da.Fill(ds, "data");
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
的鏈接不工作。 –
內部連接和外部鍵是用於不同目的的不同工具。你的問題就像問摩托車或菜刀。請做一些研究。 –
使用該表格數據,預期的結果是什麼? – jarlh