主题:“没有为命令对象设置命令”怎么解决?
问题出现在绿色那句上,在2楼我还会附上连接数据库的代码!麻烦高手帮我解决一下!谢谢
<%
' =================================================
'过程名:ShowSpecialProduct
'作 用:显示热门产品
'参 数:
'strFilter: 选择条件,有以下可选项:
' "Recommended": 推荐度
' "Cheap": 最优惠产品
'nCount:最大显示数量
' =================================================
Sub ShowSpecialProduct(strFilter, nCount)
dim strSpecialText
if strFilter = "Recommended" then
strSpecialText = "推荐精品"
elseif strFilter = "Cheap" then
strSpecialText = "最优惠精品"
end if
%>
<TABLE cellSpacing = "0" cellPadding = "0" width = "100%" border = "0" ID = "Table1">
<TBODY>
<TR>
<TD height = "20" background = "images/titlebg.gif" align = center><strong><%=strSpecialText%></strong>
</TD>
</TR>
<TR>
<TD height = "5"></TD>
</TR>
<TR>
<TD vAlign = "top">
<table width = "95%" border = "0" align = "center" cellpadding = "0" cellspacing = "0" ID = "Table2">
<tr>
<td>
<% call ShowSpecialProductList(strFilter, nCount) %>
</td>
</tr>
</table>
</TD>
</TR>
<TR>
<TD height = "5"></TD>
</TR>
</TBODY>
</TABLE>
<%
end sub
' =================================================
'过程名:ShowSpecialProductList
'作 用:显示热门产品列表数据(无修饰)
'参 数:
'strFilter: 选择条件,有以下可选项:
' "Recommended": 推荐度
' "Cheap": 最优惠产品
'nCount:最大显示数量
' =================================================
Sub ShowSpecialProductList(strFilter, nCount)
dim strSQL, rsObj, productName, i
'检查nCount的合法性
nCount = CInt(nCount)
if nCount > 20 then nCount = 20
if nCount < 1 then nCount = 1
Response.Write "<table width = '100%' border = '0' cellspacing = '0' cellpadding = '0' ID = 'Table3'>"
'根据strFilter参数组织SQL语句,
'要在排序条件的最后加入以id排序,
'否则可能因为多个记录在前面排序字段处的值相同,使得筛选出的记录数超过nCount
if strFilter = "Recommended" then
strSQL = "SELECT TOP " & nCount & " ID, [Name] FROM product "
strSQL = strSQL & " ORDER BY recommend desc, recommenddate desc, id desc"
elseif strFilter = "Cheap" then
'因为用到了除法,所以要加上对分母不为0的判断
strSQL = "SELECT TOP " & nCount & " ID, [Name], memberPrice/marketPrice AS Discount "
strSQL = strSQL & " FROM Product WHERE marketPrice <> 0 "
strSQL = strSQL & " ORDER BY memberPrice/marketPrice, id desc"
end if
[color=00FF00] set rsObj = conn.Execute(strSQL)[/color]
if rsObj.EOF And rsObj.BOF then
Response.Write "目前没有此类数据……"
end if
i = 1
'输出列表,在这里尤其要注意避免字符串拼接
do while not (rsObj.eof or err)
Response.Write "<tr><td height = 23>"
Response.Write "<img src = images/cha1.gif>"
'如果是显示最优惠产品,则显示此产品的打折的程度,否则直接显示产品名字
if strFilter = "Cheap" then
productName = i & "." & rsObj("name") & "(<font color = red>" & FormatNumber(rsObj("Discount")*10,1) & "</font>折)"
else
productName = rsObj("name")
'如果名字太长,将其截断
if len(productName) > 14 then
productName = left(productName,9)&"..."
end if
end if
Response.Write "<a href = ProductDetail.asp?id=" & rsObj("ID") & "> " & productName & "</a>"
Response.Write "</td></tr>"
i = i+1
if i>100 then exit do
rsObj.MoveNext
loop
'关闭集合,但不要关闭连接,因为其他地方可能要用
rsObj.Close()
Set rsObj = Nothing
Response.Write "</table>"
end sub
' =================================================
'过程名:ShowTheBest
'作 用:显示最新推荐精品
'参 数:无
' =================================================
Sub ShowTheBest()
dim strSQL, rsObj
dim strTemp, strSrc, strIntro
strSQL = "SELECT top 1 * FROM product "
strSQL = strSQL & " WHERE Recommend > 0 "
strSQL = strSQL & " ORDER by RecommendDate DESC, buyNum DESC, ID DESC"
set rsObj = conn.execute (strSQL)
'如果没有找到商品,则退出此过程
if rsObj.EOF and rsObj.BOF then
Response.Write "<br><br>出错啦!可能是没有检索到数据或者检索过程出错。<br><br>"
rsObj.Close()
Set rsObj = Nothing
Exit Sub
end if
'如果找到商品,则输出信息
'确定大图片URL
if rsObj("bigImg") = "nothing" then
strSrc = "images/noBigImg.gif"
else
strSrc = "bigImg/"&rsObj("bigImg")
end if
'只显示部分商品介绍,
'注意这里一定要用Convert函数对介绍内容进行HTML编码和加入换行符<br>
strIntro = Convert(rsObj("introduce"))
if lenB(strIntro)>300 then
strIntro = leftB(strIntro,300)
end if
%>
<table width = "100%" border = "0" bordercolordark = #ffffff bordercolorlight = #FFCF00 cellspacing = "0" cellpadding = "0" align = "center" ID = "Table20">
<tr>
<TD class = "tabTitle" height = "22" bgColor=<%=conTitleColor%> colspan = 2><b>推荐精品</b></TD>
</tr>
<tr><td height = 10 colspan = 2></td></tr>
<tr>
<td width = "160" align = center> <a href = ProductDetail.asp?id=<%=rsObj("id")%>>
<img src = "<%=strSrc%>" height=<%=conBigImageHeight%> border = 0></a><br>
<a href = "ProductDetail.asp?id=<%=rsObj("id")%>" title = "点击查看具体信息"><b><%=rsObj("Name")%></b></a><br> </td>
<td ><b>[精品介绍] </b><br>
<%=strIntro%><br>
<strike>市场价:<%=rsObj("marketPrice")%> 元 </strike> 商城价:<%=rsObj("memberPrice")%>元<br>
立即节省:<font color = RED><%=rsObj("marketPrice")-rsObj("memberPrice")%></font>元
<img src="images/cart.gif" width="22" height="22" />放入购物车</td>
</tr>
<tr><td height = 10 colspan = 2></td></tr>
</table>
<%
rsObj.Close()
set rsObj = Nothing
end sub
%>
[em18]
<%
' =================================================
'过程名:ShowSpecialProduct
'作 用:显示热门产品
'参 数:
'strFilter: 选择条件,有以下可选项:
' "Recommended": 推荐度
' "Cheap": 最优惠产品
'nCount:最大显示数量
' =================================================
Sub ShowSpecialProduct(strFilter, nCount)
dim strSpecialText
if strFilter = "Recommended" then
strSpecialText = "推荐精品"
elseif strFilter = "Cheap" then
strSpecialText = "最优惠精品"
end if
%>
<TABLE cellSpacing = "0" cellPadding = "0" width = "100%" border = "0" ID = "Table1">
<TBODY>
<TR>
<TD height = "20" background = "images/titlebg.gif" align = center><strong><%=strSpecialText%></strong>
</TD>
</TR>
<TR>
<TD height = "5"></TD>
</TR>
<TR>
<TD vAlign = "top">
<table width = "95%" border = "0" align = "center" cellpadding = "0" cellspacing = "0" ID = "Table2">
<tr>
<td>
<% call ShowSpecialProductList(strFilter, nCount) %>
</td>
</tr>
</table>
</TD>
</TR>
<TR>
<TD height = "5"></TD>
</TR>
</TBODY>
</TABLE>
<%
end sub
' =================================================
'过程名:ShowSpecialProductList
'作 用:显示热门产品列表数据(无修饰)
'参 数:
'strFilter: 选择条件,有以下可选项:
' "Recommended": 推荐度
' "Cheap": 最优惠产品
'nCount:最大显示数量
' =================================================
Sub ShowSpecialProductList(strFilter, nCount)
dim strSQL, rsObj, productName, i
'检查nCount的合法性
nCount = CInt(nCount)
if nCount > 20 then nCount = 20
if nCount < 1 then nCount = 1
Response.Write "<table width = '100%' border = '0' cellspacing = '0' cellpadding = '0' ID = 'Table3'>"
'根据strFilter参数组织SQL语句,
'要在排序条件的最后加入以id排序,
'否则可能因为多个记录在前面排序字段处的值相同,使得筛选出的记录数超过nCount
if strFilter = "Recommended" then
strSQL = "SELECT TOP " & nCount & " ID, [Name] FROM product "
strSQL = strSQL & " ORDER BY recommend desc, recommenddate desc, id desc"
elseif strFilter = "Cheap" then
'因为用到了除法,所以要加上对分母不为0的判断
strSQL = "SELECT TOP " & nCount & " ID, [Name], memberPrice/marketPrice AS Discount "
strSQL = strSQL & " FROM Product WHERE marketPrice <> 0 "
strSQL = strSQL & " ORDER BY memberPrice/marketPrice, id desc"
end if
[color=00FF00] set rsObj = conn.Execute(strSQL)[/color]
if rsObj.EOF And rsObj.BOF then
Response.Write "目前没有此类数据……"
end if
i = 1
'输出列表,在这里尤其要注意避免字符串拼接
do while not (rsObj.eof or err)
Response.Write "<tr><td height = 23>"
Response.Write "<img src = images/cha1.gif>"
'如果是显示最优惠产品,则显示此产品的打折的程度,否则直接显示产品名字
if strFilter = "Cheap" then
productName = i & "." & rsObj("name") & "(<font color = red>" & FormatNumber(rsObj("Discount")*10,1) & "</font>折)"
else
productName = rsObj("name")
'如果名字太长,将其截断
if len(productName) > 14 then
productName = left(productName,9)&"..."
end if
end if
Response.Write "<a href = ProductDetail.asp?id=" & rsObj("ID") & "> " & productName & "</a>"
Response.Write "</td></tr>"
i = i+1
if i>100 then exit do
rsObj.MoveNext
loop
'关闭集合,但不要关闭连接,因为其他地方可能要用
rsObj.Close()
Set rsObj = Nothing
Response.Write "</table>"
end sub
' =================================================
'过程名:ShowTheBest
'作 用:显示最新推荐精品
'参 数:无
' =================================================
Sub ShowTheBest()
dim strSQL, rsObj
dim strTemp, strSrc, strIntro
strSQL = "SELECT top 1 * FROM product "
strSQL = strSQL & " WHERE Recommend > 0 "
strSQL = strSQL & " ORDER by RecommendDate DESC, buyNum DESC, ID DESC"
set rsObj = conn.execute (strSQL)
'如果没有找到商品,则退出此过程
if rsObj.EOF and rsObj.BOF then
Response.Write "<br><br>出错啦!可能是没有检索到数据或者检索过程出错。<br><br>"
rsObj.Close()
Set rsObj = Nothing
Exit Sub
end if
'如果找到商品,则输出信息
'确定大图片URL
if rsObj("bigImg") = "nothing" then
strSrc = "images/noBigImg.gif"
else
strSrc = "bigImg/"&rsObj("bigImg")
end if
'只显示部分商品介绍,
'注意这里一定要用Convert函数对介绍内容进行HTML编码和加入换行符<br>
strIntro = Convert(rsObj("introduce"))
if lenB(strIntro)>300 then
strIntro = leftB(strIntro,300)
end if
%>
<table width = "100%" border = "0" bordercolordark = #ffffff bordercolorlight = #FFCF00 cellspacing = "0" cellpadding = "0" align = "center" ID = "Table20">
<tr>
<TD class = "tabTitle" height = "22" bgColor=<%=conTitleColor%> colspan = 2><b>推荐精品</b></TD>
</tr>
<tr><td height = 10 colspan = 2></td></tr>
<tr>
<td width = "160" align = center> <a href = ProductDetail.asp?id=<%=rsObj("id")%>>
<img src = "<%=strSrc%>" height=<%=conBigImageHeight%> border = 0></a><br>
<a href = "ProductDetail.asp?id=<%=rsObj("id")%>" title = "点击查看具体信息"><b><%=rsObj("Name")%></b></a><br> </td>
<td ><b>[精品介绍] </b><br>
<%=strIntro%><br>
<strike>市场价:<%=rsObj("marketPrice")%> 元 </strike> 商城价:<%=rsObj("memberPrice")%>元<br>
立即节省:<font color = RED><%=rsObj("marketPrice")-rsObj("memberPrice")%></font>元
<img src="images/cart.gif" width="22" height="22" />放入购物车</td>
</tr>
<tr><td height = 10 colspan = 2></td></tr>
</table>
<%
rsObj.Close()
set rsObj = Nothing
end sub
%>
[em18]