您当时的方位:主页 > 言语编程 > ASP.NET

这是asp.net的第二个使用(五)

2014-10-28  
/*
豆腐制造,都是精品
http://www.asp888.net 豆腐技能站
如转载,请保存完好版权信息
*/
好了,截止到这儿,咱们基本上能够说是 公德圆满了!咱们能够歇息歇息了,咱们在本章中所讲的内容
便是做一个 专栏办理的 主页,主页应该包含 一切的栏目类别,最近的10篇文章和最抢手的10篇文章
咱们现在来看看这个原本第一个写的aspx文件:default.aspx
<!--#include file="func.aspx"-->
<script language=vb runat=server>
sub WriteLanmuClass()
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim sRead as SQLDataReader
strSQL="select * from lanmuclass"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.open()
sqlCmd.execute(sRead)
dim i as integer
response.write("<table border=1 width=100%><tr><td>")
while(sRead.Read())
response.write("<a href=showarticle.aspx?classid=" & sRead("classid") & ">" & sRead("classname") & "</a>(<font color=red>" & GetClassNum(cStr(sRead("classid"))) & "</font>)")
end while
response.write("</td></tr></table>")
end sub
function GetClassNum(strClassId as string) as string
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim numRead as SQLDataReader
strSQL="select count(*) as ccount from lanmu where classid='" & strClassId & "'"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.Open()
sqlCmd.Execute(numRead)
numRead.Read()
GetClassNum=numRead(0)
end function

sub WriteLastArticle()
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim sRead as SQLDataReader
strSQL="select top 10 * from lanmu,lanmuclass where lanmu.classid=lanmuclass.classid and lanmu.isuse='1' order by id desc"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.open()
sqlCmd.execute(sRead)
response.Write("<p><font color=gray>最近的文章</font></p>")
response.Write("<table border=0 width=100%>")
while(sRead.Read())
response.Write("<tr>")
response.Write("<td width=100% align=left>")
response.Write("[<a href='showarticle.asp?classid=" & sRead("classid") & "'>" & sRead("classname") & "</a>]")
response.Write("<a href='viewarticle.asp?id=" & sRead("id") & "' target='_blank'>" & sRead("title") & "</a><font color=gray size=1>" & sRead("dtime") & "</gray>")
response.Write("</td>")
response.Write("</tr>")
End While
response.Write("</table>")
end sub

sub WriteMostClick()
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim sRead as SQLDataReader
strSQL="select top 10 * from lanmu,lanmuclass where lanmu.classid=lanmuclass.classid and lanmu.isuse='1' order by viewnum desc"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.open()
sqlCmd.execute(sRead)
response.Write("<p><font color=gray>最近的文章</font></p>")
response.Write("<table border=0 width=100%>")
while(sRead.Read())
response.Write("<tr>")
response.Write("<td width=100% align=left>")
response.Write("[<a href='showarticle.asp?classid=" & sRead("classid") & "'>" & sRead("classname") & "</a>]")
response.Write("<a href='viewarticle.asp?id=" & sRead("id") & "' target='_blank'>" & sRead("title") & "</a><font color=gray size=1>" & sRead("dtime") & "</gray>")
response.Write("</td>")
response.Write("</tr>")
End While
response.Write("</table>")
end sub
</script>
<html>
<head>
<title>豆腐技能站-->技能专栏</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Description" Content="讨论ASp,Php 编程,介绍Visual Basic ,Visual C++
等业界