如何用两个表绑定gridview [英] How to bind gridview with two table
本文介绍了如何用两个表绑定gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个名为cpu的表并且我想在gridview中获取数据
表cpu有名称,image1
表卖得有成本,品牌
I have two table named cpu and sell and i want to get data in gridview
table cpu has name,image1
table sell has cost,brand
SqlCommand cmd = new SqlCommand("SELECT name,image1,Min(cost),MAX(cost) FROM sell,cpu WHERE cpu.name=sell.brand", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
但运行时会出现此错误
不明确的列名'name'。
推荐答案
试试这个:
Try this:
SqlCommand cmd = new SqlCommand("SELECT cpu.name,image1,Min(cost),MAX(cost) FROM sell,cpu WHERE cpu.name=sell.brand group by(cpu.name)", con);
>
这篇关于如何用两个表绑定gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文