当前位置: 代码迷 >> ASP.NET >> GridView怎的绑定不同表中的不同字段
  详细解决方案

GridView怎的绑定不同表中的不同字段

热度:5109   发布时间:2013-02-25 00:00:00.0
GridView怎样绑定不同表中的不同字段
GridView怎么绑定不同表中的不同字段?????????

------解决方案--------------------------------------------------------
探讨
GridView怎么绑定不同表中的不同字段?????????

------解决方案--------------------------------------------------------
GridView负责显示数据了,其他的逻辑单独处理了
比如我建立了一个视图,视图里面是几个表的联合查询
SQL code
CREATE VIEW dbo.cg_purchaseASSELECT a.[ID], a.DeptID,h._Name as Dept,a.BillID, Type=CASE WHEN a.Type=1 THEN '采购' ELSE '退货' END, _Date=convert(char(10),a._Date,120), a.OperatorID, a.ProvID, a.StockID,       ChkDate=convert(char(10),a.ChkDate,120), a.ChkOperatorID,Status=CASE WHEN a.Status=1 THEN '待审核' ELSE '已审核' END, a.Remark,       b.JobNO AS OperatorNO, b._Name AS Operator, e.SupNO, e._Name AS Provider,       d._Name AS StockName, c.JobNO AS ChkOperatorNO, a.InCash,      c._Name AS ChkOperator,e.pyCode as ProviderCode,a.OperationID,dbo.aa_gettotalprofit(a.[ID],6) as Total,dbo.aa_gettotalprofit(a.[ID],9) as GoodsAmount,a.OperationBillFROM dbo.Purchase a LEFT OUTER JOIN      dbo.StaffList b ON a.OperatorID = b.[ID] LEFT OUTER JOIN      dbo.StaffList c ON a.ChkOperatorID = c.[ID] LEFT OUTER JOIN      dbo.StockList d ON a.StockID = d.[ID] LEFT OUTER JOIN      dbo.SupplierList e ON a.ProvID = e.[ID] LEFT OUTER JOIN      dbo.BranchList h ON a.DeptID=h.[ID]
------解决方案--------------------------------------------------------
就是在sql查询的时候就多表查询
SELECT t1.id,t2.name from [idtable] t1
join [nametable] on t1.id=t2.id

这样返回的就是两个表的连接结果