<!--metadata type="typelib" file="c:\program files\common files\system\ado\msado15.dll"-->
<%'接收用户输入的查询条件
sex=Request.Form("sex")
department=Request.Form("department")
If sex="" OR department="" Then
  Response.Redirect "commselect.htm"
End If
'创建数据库连接
Set conn=Server.CreateObject("ADODB.Connection")
strProvider="Provider=SQLNCLI;Data Source=localhost;Initial Catalog=person; User ID=sa; Password=123;"
conn.Open strProvider
'创建Command对象并设置其属性
Set comm=Server.CreateObject("ADODB.Command")
comm.ActiveConnection=conn
'SQL语句中用?表示将接收Parameter对象所传递的参数
comm.CommandText="SELECT * FROM t_teacher WHERE sex=? AND department=?"
comm.CommandType=adCmdText
comm.Prepared=True
'建立Parameters数据集合
Set params=comm.parameters
'建立第一个Parameter对象,并用变量sex为其赋值
Set sex=comm.CreateParameter("sex",adVarChar,adParamInput,2,sex)
'将新建的Parameter对象追加到Parameters数据集合中
Params.Append sex
'建立第二个Parameter对象
Set num=comm.CreateParameter("department",adVarChar,adParamInput,10, department)
Params.Append num
set rs=comm.Execute()
'显示查询结果代码
If NOT rs.EOF Then
  While NOT rs.EOF
     Response.Write "<TABLE border=3>"
     Response.Write "查询结果为：<BR><TR>"
     For i=0 To rs.fields.count-1
         Response.Write "<TD>" & rs(i).value & "</TD>"
     Next
     rs.MoveNext
     Response.Write "<TR>"
  Wend
Else
  Response.Write "对不起，没有找到匹配的结果！<BR>"
End If
Set conn=nothing   %>
