LINQ TO SQL 中多表查询问题(急求)
class表:
CREATE TABLE CLASS(
classID INT IDENTITY(1,1) NOT NULL,
adress varchar(50) not null,
subject varchar(20) not null
primary key(classID)
)
students表:
CREATE TABLE student(
ID INT IDENTITY(1,1) NOT NULL,
sno int not null,
[sname] varchar(20) not null,
classID INT NOT NULL,
invID INT NOT NULL
PRIMARY KEY(ID),
foreign key(classID) REFERENCES CLASS(classID),
foreign key(invID) references teacher(invID)
)
teacher表:
create table teacher
(
invID INT IDENTITY(1,1) NOT NULL,
[name] varchar(20) not null,
primary key(invID),
)
要查询关键字 sno 显示为:
sno sname adress subject sname的形式。高手帮忙看下我哪里错了???
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" onrowcommand="GridView2_RowCommand">
<Columns>
<asp:TemplateField HeaderText="学号" SortExpression="sno">
<ItemTemplate>
<asp:Label ID="Label_ID" runat="server" Text='<%#Eval("sno") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="考生名" SortExpression="sname">
<ItemTemplate>
<asp:Label ID="Label_load" runat="server" Text='<%#Eval("sname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="教室" SortExpression="class">
<ItemTemplate>
<asp:Label ID="Label_price" runat="server" Text='<%#Eval("adress") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="科目" SortExpression="subject">
<ItemTemplate>
<asp:Label ID="Label_stay" runat="server" Text='<%#Eval("subject") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="监考" SortExpression="name">
<ItemTemplate>
<asp:Label ID="Label_traffic" runat="server" Text='<%#Eval("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
cs内:
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
var tr = from a in db.students
join b in db.CLASS on a.classID equals b.classID
join c in db.teacher on a.invID equals c.invID
where a.sno == Session["sno"]
select new
{
a.sno,
a.sname,
b.adress,
b.subject,
c.name,
};
GridView2.DataSource = tr;
GridView2.DataBind();
}
急求!!!!!!!!!!!!!!!
------解决方案--------------------
建议开启调试,查看TR中是否成功查询,以及SESSION中是否有对应的值。