| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1134 人关注过本帖
标题:请教SQL语句
只看楼主 加入收藏
badskf
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-12-21
收藏
得分:0 
这样改后可以了,谢谢google的帮助
2005-12-21 12:29
阳光白雪
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:39
帖 子:2220
专家分:0
注 册:2005-11-18
收藏
得分:0 
ygxm=request("ygxm")
adddate=request("adddate")


dim result

result = "1=1"
if ygxm<>"" the
result=result &" and ygxm = '"&ygxm&"'"
end if
if adddate<>"" the
result= result&"and adddate = '"&adddate&"'"
end if
sql="select * from 表 where "&result&""


专注于WEB前端交互平台开发:[url=http://blog./]blog.[/url](富客户端技术(RIA)交流平台)
2005-12-21 13:01
badskf
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-12-21
收藏
得分:0 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/gz.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>66666</td>
</tr>
<tr>
<td><form name="form1" method="post" action="test.asp">
姓名:
<input name="ygxm" type="text" id="ygxm">
年月:
<input name="adddate" type="text" id="adddate">
<input type="submit" name="Submit" value="提交">
</form></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<%
dim ygxm,adddate,rs
ygxm=request.form("ygxm")
adddate=request.form("adddate")

if ygxm<>"" and adddate="" then
sql="select * from dbo.hz where ygxm = '"&ygxm&"'" '这个比较根据你的实际情况写比较符号
end if
if ygxm="" and adddate<>"" then
sql="select * from dbo.hz where adddate like '%"+ adddate + "%'" '这个比较根据你的实际情况写比较符号
end if
if ygxm<>"" and adddate<>"" then
sql="select * from dbo.hz where ygxm = '"&ygxm&"' and adddate like '%"+ adddate + "%'" '这个比较根据你的实际情况写比较符号
end if

set rs=Server.CreateObject("ADODB.RecordSet")
rs.ActiveConnection = MM_gz_STRING
rs.Source = sql
rs.CursorType = 1
rs.CursorLocation = 3
rs.LockType = 3
rs.Open()

rs.PageSize = 20
'这里设定每页显示的记录数
pre = true
last = true
page = trim(Request.QueryString("page"))

if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<% If Not rs.EOF Or Not rs.BOF Then %> <tr><%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%><td><%=rs.Fields.Item("ygxm")%></td>
</tr><%
rs.MoveNext()
next
%> <% End If ' end Not rs1.EOF Or NOT rs1.BOF %>

<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>



全文如下,我想通过表单提交参数查询,可是出现如下错误

错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E0C)
没有为命令对象设置命令。
/shoes/test.asp, 第 49 行

2005-12-21 13:14
badskf
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-12-21
收藏
得分:0 


<!--#include file="Connections/gz.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>66666</td>
</tr>
<tr>
<td><form name="form1" method="post" action="test.asp">
姓名:
<input name="ygxm" type="text" id="ygxm">
年月:
<input name="adddate" type="text" id="adddate">
<input type="submit" name="Submit" value="提交">
</form></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<%
dim ygxm,adddate,rs
ygxm=request.form("ygxm")
adddate=request.form("adddate")

if ygxm<>"" and adddate="" then
sql="select * from dbo.hz where ygxm = '"&ygxm&"'" '这个比较根据你的实际情况写比较符号
end if
if ygxm="" and adddate<>"" then
sql="select * from dbo.hz where adddate like '%"+ adddate + "%'" '这个比较根据你的实际情况写比较符号
end if
if ygxm<>"" and adddate<>"" then
sql="select * from dbo.hz where ygxm = '"&ygxm&"' and adddate like '%"+ adddate + "%'" '这个比较根据你的实际情况写比较符号
end if

set rs=Server.CreateObject("ADODB.RecordSet")
rs.ActiveConnection = MM_gz_STRING
rs.Source = sql
rs.CursorType = 1
rs.CursorLocation = 3
rs.LockType = 3
rs.Open()

rs.PageSize = 20
'这里设定每页显示的记录数
pre = true
last = true
page = trim(Request.QueryString("page"))

if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<% If Not rs.EOF Or Not rs.BOF Then %> <tr><%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%><td><%=rs.Fields.Item("ygxm")%></td>
</tr><%
rs.MoveNext()
next
%> <% End If ' end Not rs1.EOF Or NOT rs1.BOF %>

<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>

全文如下,我想通过表单提交参数查询,可是出现如下错误错误类型:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E0C)没有为命令对象设置命令。shoes/test.asp, 第 49 行

第49行为“rs.Open()”

2005-12-21 13:16
badskf
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-12-21
收藏
得分:0 
请问阳光白雪:

result = "1=1"
if ygxm<>"" the
result=result &" and ygxm = '"&ygxm&"'"
end if
if adddate<>"" the
result= result&"and adddate = '"&adddate&"'"
end if
sql="select * from 表 where "&result&""
2005-12-27 11:49
快速回复:请教SQL语句
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017003 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved