我有2张桌子。
Branches (BranchId,Name, Area)
Managers (ManagerId,Name,BranchId)
我希望当我点击分支时,分支数据将显示为经理姓名。我使用gridview
来显示数据。
<asp:GridView runat="server" ClientIDMode="Static" ID="gvBranches">
</asp:GridView>
首先我写LINQ查询。
CDDataContext dc = new CDDataContext();
var data = (from branch in dc.Branches
join manager in dc.Managers
on branch.BranchId equals manager.BranchId
select branch).ToList();
gvBranches.DataSource = data;
gvBranches.DataBind();
它只显示分支记录。比如BranchId Name Area
然后我写了存储过程。
存储过程:
create procedure sp_AllBranches
As
Begin
return Select b.BranchId, b.Name, b.Area, m.Name
from Branches as b, Managers as m
where b.BranchId=m.BranchId
End
代码:
CDDataContext dc = new CDDataContext();
var data = dc.sp_AllBranches();
gvBranches.DataSource = data;
gvBranches.DataBind();
它什么也没显示。请帮忙。