datagrid 明细表显示问题???
我想实现 第一行 显示商品类别名 紧接着 第二行显示 该商品类别里的具体商品
其中表 ProType 中字段 PTypeName PType(商品类编号) 表Products Pname(商品名) PTypeId (商品类编号 与 表ProType 中 PType 对应)
代码如下 (运行时没错误,就是datagrid 里不显示任何内容)
请各位师兄 指出错误!! 谢谢!!
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["strConnection"].ToString());
//创建数据适配器对象
SqlDataAdapter da = new SqlDataAdapter("select * from ProType select Products.Pname, PTypeName, PTypeId from Products,ProType where Products.Ptype=ProType.PTypeId ",conn);
//创建DataSet对象
DataSet ds = new DataSet();
try
{
//填充数据集
da.Fill(ds);
//设定表名字
ds.Tables[0].TableName = "ProType";
ds.Tables[1].TableName = "Products";
DataColumn Parent = ds.Tables["ProType"].Columns["PtypeId"];
DataColumn Child = ds.Tables["Products"].Columns["PTypeId"];
DataRelation tableRelation = new DataRelation("tableRelation", Parent, Child, false);
ds.Relations.Add(tableRelation);
//进行数据绑定
DataGrid1.DataSource = ds.Tables["Products"].DefaultView;
DataGrid1.DataBind();
}
catch(Exception error)
{
Response.Write(error.ToString());
}