A表
id, buyid,product,money
1 1 pen 10
2 1 age 20
3 1 apple 30
B表
id buyid,user
1 1 KOF
上面表A是商品购买明细,下面是订单buyid就是订单号
现在要绑定到GridView后
buyid,product_breif,allmoney,user
1 pen,age,apple 60 kof
-------------------------------------------
求两种方式
一种是直接SQL查询:
-----------------------
另一种是先绑定B表再根据B表的buyid绑定A表的数据到product_breif,allmoney
谢谢
1 楼mincunbao(衝動是魔鬼)回复于 2006-12-22 15:43:30 得分 20
Create function GatherSize(@style varchar(8),@color varchar(4))
returns varchar(500)
as
begin
declare @s varchar(500)
set @s=''
select @s=@s+','+ProductSize from Product where
(ProductColor=@color or @color is null or @color='')
and (ProductStyle=@style or @style is null or @color='')
set @s=right(@s,len(@s)-1)
return (@s)
end
运行:
select ProductStyle,ProductColor,ProductSize=dbo.GatherSize(ProductStyle,ProductColor)
from Product group by ProductStyle,ProductColor
和這個差不多,你試試,你的沒去調試,不過結果差不多,那個合計加一下就可以了
這個主要實現 pen,age,apple 這種效果,其他就簡單了Top
2 楼zyciis42()回复于 2006-12-22 15:44:47 得分 0
大哥,我的是ACCESS没有存储过程的谢谢Top
3 楼net_lover(【孟子E章】)回复于 2006-12-22 15:50:33 得分 10
你可以 放到一个DataSet里,这样不用多次查询数据库Top
4 楼zyciis42()回复于 2006-12-22 15:55:24 得分 0
问题一:
主要是想知道怎样把pen,age,apple查出其他的都好办
问题二:
我是在aspx里面再加多一个过程得到的
如aspx:
<%# getShop(DataBinder.Eval(Container.DataItem,"id").ToString())%>
aspx.cs
protected string getShop(String s)
{
....
}
但我想有没有什么办法不用在aspx而比如在aspx.cs中的ItemDataBound中要怎么写Top
5 楼zyciis42()回复于 2006-12-22 16:06:25 得分 0
UPTop
6 楼hy_lihuan(我想早恋,可是已经晚了)回复于 2006-12-22 16:13:01 得分 10
这个不知道怎么写,关注中;Top
7 楼zyciis42()回复于 2006-12-22 16:34:30 得分 0
UPTop
8 楼zyciis42()回复于 2006-12-22 16:51:33 得分 0
upTop
9 楼zyciis42()回复于 2006-12-22 21:52:12 得分 0
UPTop
10 楼cpp2017(慕白兄)回复于 2006-12-22 22:06:34 得分 30
可以.
不过access要查两次.
sql = "select B.id,B.user,sum(A.money) as allmoney from a,b where a.budid = b.buyid group by B.id,B.user"
sql = "select * from a"
这样生成两个表 dtA,和dtB
dtA.Columns.Add("product_breif");
gridview 绑定dtA表.
在GridView1_RowDataBound 事件中
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//假设第一列是
DataTable dtB;
DataRow[] rows = dtB.Select("buyid='" + e.Row.Cells[0].Text+"'");
string str = "";
for (int i = 0; i < rows.Length; i++)
{
str += rows[i]["product"].ToString() + ",";
}
if (str != "")
{
str = str.Substring(0, str.Length - 1);
}
e.Row.Cells[1].Text = str;
}
}
Top
11 楼zyciis42()回复于 2006-12-22 22:27:17 得分 0
sql = "select B.id,B.user,sum(A.money) as allmoney from a,b where a.budid = b.buyid group by B.id,B.user"
sql = "select * from a"
这样生成两个表 dtA,和dtB
dtA.Columns.Add("product_breif");
最后的
dtA.Columns.Add("product_breif");是什么意思要怎么写Top
12 楼zyciis42()回复于 2006-12-22 22:33:56 得分 0
那如果是SQL不通过存储过程可不可以一条写
谢谢Top
13 楼zyciis42()回复于 2006-12-22 23:52:15 得分 0
UPTop
14 楼liujia_0421(SnowLover)回复于 2006-12-23 01:00:19 得分 10
TO:那如果是SQL不通过存储过程可不可以一条写
不行,如果不想用存过,那还是自己一条条写吧..