BLL层:
protected void Button1_Click(object sender, EventArgs e)
{
IQueryable results;
if (BLL.UserBLL.lainjie (out results))
{
GridView1.DataSource = results;
GridView1.DataBind();
}
}
DAL层:
public static IQueryable lj()
{
var results = from r in db.Score
join s in db.Student on r.Sno equals s.Sno
join c in db.Course on r.Cno equals c.Cno
select new
{
r.Sno,
r.Cno,
r.EndScore,
r.Course,
Sname = s.Sname,
Cname = c.Cname
};
return results;
}
Moodle层就不放了
UI层:
前台:
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="三表连接" />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:schoolConnectionString %>" SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>
注:这个可以不用看。
后台:
protected void Button1_Click(object sender, EventArgs e)
{
IQueryable results;
if (BLL.UserBLL.lainjie (out results))
{
GridView1.DataSource = results;
GridView1.DataBind();
}
}
你可以跟踪一下数据库,看一下log
BLL放错代码了吧
会不会是,你dal层和bll层没有引用好
result.tolist(); 只有到tolist 才是真正执行查询,前面的一大段都是在组sql