目前我有
public void bindgrid()
{
SqlConnection conn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True");
SqlCommand cmd = new SqlCommand("select p.[name], cd.CustomerName, cd.CustomerEmailID,cd.CustomerPhoneNo,cd.CustomerAddress,cd.TotalPrice,cd.OrderDateTime, cd.PaymentMethod FROM CustomerDetails cd Inner Join CustomerProducts cp ON cp.CustomerID = cd.Id Inner Join Products p ON cp.ProductID = p.ProductID", conn);
SqlDataAdapter da = new SqlDataAdapter("", conn);
da.SelectCommand = new SqlCommand("select p.[name], cd.CustomerName, cd.CustomerEmailID,cd.CustomerPhoneNo,cd.CustomerAddress,cd.TotalPrice,cd.OrderDateTime, cd.PaymentMethod FROM CustomerDetails cd Inner Join CustomerProducts cp ON cp.CustomerID = cd.Id Inner Join Products p ON cp.ProductID = p.ProductID", conn);
DataSet ds = new DataSet();
da.Fill(ds, "data");
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
结果:
我想要发生的是,因为它在同一个ID(10)中,如果我的Name列中可以有多个值,是否可以?像lpg,氧气等?
更新:到目前为止我得到了
我只想在我的名称列中存储多个值以避免冗余。请帮忙
答案 0 :(得分:1)
将您的交易与项目分成两个单独的表格。在项目购买表中使用事务ID作为外键。那就是:
name
name
和Id
Id
Id
和各种名称所以你的第二个表将包含行:
Id name
...
10 Carbon Dioxide
10 Industrial Oxygen
11 (a different purchase)
11 (a different purchase)
...