Asp问题: 根据输入的字符串查找数据库?

来源:百度知道 编辑:UC知道 时间:2024/06/03 17:47:39
在表单文本框中输入字符如:11-03-05 要从数据库中三个字段oneid,twoid,threeid里找出
符合11,03,05的记录。
我的想法是:从输入的字符串中取出三个数,存到一个数组里面,然后从数组三个元素分别和数据库
中的oneid,twoid,threeid三个字段的值比较找出符合条件的记录。

注:数据库的oneid,twoid,threeid三个字段都为int型。

表单:
<table width="600" >
<tr align="center">
<form name="form1" method="post" action="Search.asp?action=Find">
<td height="35" >选择查询方式:
<select name="select">
<option value="Name" selected>名称</option>
<option value="DossierID">按输入ID号查询 </option>
</select>
<input name="key" type="text" size="30">
<input type="submit" name="Submit" value="查询">

<%
Set Rs = Server.CreateObject("ADODB.Recordset")
If Request("action") = "Find" Then
key = Trim(Request("key"))
If Request("select") = "Name" Then
Sql = "Select * From Content Where Name Like '%"&key&"%' Order By Time Desc"
ElseIf Request("select") = "DossierID" Then
DossierIDArray=Split(key,"-")
sql="select * from Content Where oneid="&CInt(DossierIDArray(0))&" and twoid="&CInt(DossierIDArray(1))&" and threeid="&CInt(DossierIDArray(2))&" order by Time Desc"
Else
Response.Write "<Script>alert('查询错误!');</Script>"
Response.End
End If
Else
Sql = "Select * From Content Order By Time Desc"
End If
Rs.Open Sql,conn,3,3
%>