Asp 这种情况下字符转换成日期型怎么转换?
在表单文本框中输入时间如:2008-10-06的查询代码如下:表单:<tablewidth="600"><tralign="center"><formname="form...
在表单文本框中输入时间如:2008-10-06的查询代码如下:
表单:
<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="Time">按输入时间查询 </option>
</select>
<input name="key" type="text" size="30">
<input type="submit" name="Submit" value="查询">
</td>
</form>
</tr>
</table>
具体查询
<%
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") = "Time" Then
Sql = "Select * From Content Where Time Like '%"&key&"%' 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
%>
注:数据库的time字段类型是smalldatetime
第一个名称查询没有问题,第二个需要通过字符转换成时间型,不能解决。 展开
表单:
<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="Time">按输入时间查询 </option>
</select>
<input name="key" type="text" size="30">
<input type="submit" name="Submit" value="查询">
</td>
</form>
</tr>
</table>
具体查询
<%
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") = "Time" Then
Sql = "Select * From Content Where Time Like '%"&key&"%' 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
%>
注:数据库的time字段类型是smalldatetime
第一个名称查询没有问题,第二个需要通过字符转换成时间型,不能解决。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询