有两个表
item(itemid,itemname)
info(id,itemid,title,...)
我原来在主页是这样写的:
string sql3 = "select top 8 * from [info] where classid=2 order by [id] desc"
现在想在这个查询语句中同时显示item中的itemname,不知怎么写?请教高手,谢谢!!
item(itemid,itemname)
info(id,itemid,title,...)
我原来在主页是这样写的:
string sql3 = "select top 8 * from [info] where classid=2 order by [id] desc"
现在想在这个查询语句中同时显示item中的itemname,不知怎么写?请教高手,谢谢!!
select a.itemid,a.itemname,b.title
from item a inner join info b
on a.itemid=b.itemid
select top 8 a.*,b.itemname from [info] a inner join [item] b on a.itemid=b.itemid where a.classid=2 order by a.[id] desc
至少一个参数没有被指定值
是不是接下来的代码也要修改?
OleDbDataAdapter da3 = new OleDbDataAdapter(sql3, conn);
DataSet ds3= new DataSet();
da3.Fill(ds3, "info");
this.DataList3.DataSource = ds3.Tables["info"].DefaultView;
this.DataList3.DataBind();
怎么修改?谢谢!!
我是这样写的
string sql4 = "select a.itemid as itemid,itemname,title from item a inner join info b on a.itemid=b.itemid where a.classid=1 order by a.[id] desc";//通知下载
OleDbDataAdapter da4 = new OleDbDataAdapter(sql4, conn);
DataSet ds4= new DataSet();
da4.Fill(ds4, "info");
this.DataList4.DataSource = ds4.Tables["info"].DefaultView;
this.DataList4.DataBind();
<asp:DataList ID="DataList4" runat="server" Width =270>
<ItemTemplate>
<TABLE class=line20px cellSpacing=0
cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD class=line22px height=22><DIV
style="LINE-HEIGHT: 26px; BORDER-BOTTOM: #cccccc 1px dashed"><IMG height=9
src="images/ring01.gif" > <a href='Show.aspx?nid=<%#Eval("nclassid")%>&id=<%#Eval("id")%>' > <%# Eval("Title").ToString().Length > 17 ? Eval("Title").ToString().Substring(0, 17) : Eval("Title")%></a>
<font color="#949494">[<%# String.Format("{0:MM-dd}", Eval("intime"))%>]</font></DIV></TD></TR>
</TBODY></TABLE></ItemTemplate>
</asp:DataList>
可右击DataList控件属性 看它的DataKeyField中有哪些可选字段
在DetailsView中出现过这个问题,DataKeyNames属性设为主键解决了