当前位置:编程学习 > C#/ASP.NET >>

初学者求教


诚心求教高手,怎么把下面的查询转换成参数化查询?T_CataID, T_Words, T_Num, T_Pic, T_Count, T_Date, T_More是从ASP页面传递过来的变量。

<!--#include file = "../Include/DBClass.inc.asp"-->


<%
Dim T_CataID, T_Words, T_Num, T_Pic, T_Count, T_Date, T_More, t_color,t_ppic,T_Special,TempContent
T_CataID = GetSafeStr(Trim(Request("Cataid")))
T_Words = GetSafeInt(Trim(Request("Words")),15)
T_Num = GetSafeInt(Trim(Request("Num")),8)
T_Pic = GetSafeInt(Trim(Request("Pic")),7)
T_ppic = GetSafeint(Trim(Request("L_p")),11)
T_Count = GetSafeStr(Trim(Request("L_C")))
T_Date = GetSafeStr(Trim(Request("L_D")))
T_More = GetSafeStr(Trim(Request("L_M")))
T_Special=GetSafeStr(Trim(Request("L_S")))
T_color = GetSafeStr(Trim(Request("L_r")))



  

If T_CataID <> "" then
Dim dRs, dSql, Flag
Set dRs = Server.CreateObject( "ADODB.Recordset" )
dSql = "SELECT * FROM NewsCata WHERE C_RootID = '"&T_CataID&"'"
dRs.Open dSql, oConn, 0, 1
If dRs.EOF Then
Flag = 1
End If
dRs.Close
Set dRs = Nothing
Else
Flag = 1
End If

TempContent="<table cellspacing=0 cellpadding=0 width=88% align=center border=0>"
TempContent=TempContent&"  <tbody>"
TempContent=TempContent&"  <tr>"
TempContent=TempContent&"    <td height=4></td>"
TempContent=TempContent&"  </tr>"

If Flag = 1 Then
TempContent=TempContent&" <tr><td>此信息类别并不存在!</td></tr>"
Else
Dim fRs, fSql, AtempTitle, o_Char
Set fRs = Server.CreateObject( "ADODB.Recordset" )

If T_Special = "ok" Then
'fSql = "SELECT TOP "&T_Num&" * FROM NewsData WHERE D_CataID LIKE '"&T_CataID&"%' And D_Special =1 ORDER BY D_SortID DESC"
fSql = "SELECT TOP "&T_Num&" * FROM NewsData WHERE D_CataID LIKE '"&T_CataID&"%' ORDER BY D_SortID DESC"
Else
fSql = "SELECT TOP "&T_Num&" * FROM NewsData WHERE D_CataID LIKE '"&T_CataID&"%' ORDER BY D_SortID DESC"
End If
if t_count="ok" then
                    fSql = "SELECT TOP "&T_Num&" * FROM NewsData WHERE D_CataID LIKE '"&T_CataID&"%' ORDER BY D_hits DESC"
end if   
fRs.Open fSql,oConn,0,1
If fRs.EOF or fRs.BOF Then
TempContent=TempContent&" <tr><td>暂时没有任何信息!</td></tr>"
End If

Do While Not fRs.EOF
If Len(Trim(fRs("D_Title"))) > Cint(T_Words) Then
AtempTitle = Left(Trim(fRs("D_Title")),T_Words)&"..."
    Else
AtempTitle = Trim(fRs("D_Title"))&"。"
End If

If T_Count = "ok" Then
If t_date= "ok" Then
o_Char ="["&FormatDateTime(fRs("D_AddTime"),vbshortdate)&" 浏览:"&fRs("D_Hits")&"]"
Else
o_Char ="[浏览:"&fRs("D_Hits")&"]"
End If
Else
If T_Date= "ok" Then

                                                  o_char= Datepart("m",fRs("D_AddTime"))&"-"&Datepart("d",fRs("D_AddTime")) 

Else
o_Char =""
End If
End If

tcolor2=t_color
tcolor1="#"&tcolor2
tppic1=chr(t_ppic)

TempContent=TempContent&"  <tr>" 
TempContent=TempContent&"    <td height=10 width=8align=left' valign='middle'> "
TempContent=TempContent&" <font size='2' color='#94c4eb'>"&tppic1&"</font>"
TempContent=TempContent&"    </td>"


 TempContent=TempContent&"    <td height=10  valign='top'> "
TempContent=TempContent&"      <a href='"&RootUrl&"/News/Show.asp?id="&fRs("D_ID")&"' target=_blank><font color='"&tcolor1&"'>"&AtempTitle&"</font></a></td><font color='#94c4eb'>"&o_char&"</font>"


TempContent=TempContent&"    </td>"
TempContent=TempContent&"  </tr>"
fRs.MoveNext
Loop
fRs.Close
Set fRs = Nothing
If T_More <> "ok" Then
TempContent=TempContent&"  <tr>"
TempContent=TempContent&"    <td height=10 width=8> "

TempContent=TempContent&"    </td>"
if t_more<>"ok" then

 TempContent=TempContent&"    <td height=10 > "
TempContent=TempContent&"      <div align=right> <a href="&RootUrl&"/News/default.asp?cataid="& T_CataID &"><font color='#5B6C79'>【更多内容】</font></a>"
TempContent=TempContent&"      </div>"
TempContent=TempContent&"    </td>"
else 
TempContent=TempContent
end if
TempContent=TempContent&"  </tr>"
End If
End If
TempContent=TempContent&"  </tbody>"
TempContent=TempContent&"</table>"
Call DBConnEnd()
%>
document.write("<%=TempContent%>"); --------------------编程问答-------------------- Parameters? --------------------编程问答-------------------- 是用Parameters 
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,