asp 多条件查询sql数据库 点查询没有显示出来

作者&投稿:孛杭 (若有异议请与网页底部的电邮联系)
我想做一个多条件查询asp界面,但是查询后没有结果,也没有报错,求高手解答~

sql_text="select * from card2 where "
那句话里的不是*。。。。。
改成sql_text="select * from card2 where "
看看

按照图片,就是得建立三个input文本框,字段,提交检索的时候获取三个字段值,通过where sql语句过滤

sid = request("sid") '学号
sname = request("sname") '学生名称
szhuanye = request("szhuanye") '专业


'判断字段是否有输入文字,链接查询
sql = "select * from s where sname ''" '先写个判断条件,省的下面得在做是否加and条件查询

if sid "" then
sql = sql + " and sid = " & sid

end
if sname "" then
sql = sql + " and sname like '%& sname &%'

end
if szhuanye "" then
sql = sql + " and szhuanye like '%& szhuanye &%'

end
首先建立oledb数据库链接,
其次创建记录集对象,写好条件查询sql,打开记录集,
最后使用while wend循环输出记录

大致步骤如下:

dataaccess = server.mappath("data/xxx.mdb")
'连接OLEDB
Set oConn = Server.CreateObject("ADODB.CONNECTION")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dataaccess

最后使用的时候都是先建立rs对象,写好sql,打开记录集就可以取数据了
set rsTemp=Server.CreateObject("adodb.recordset")
sql = "select top 10 * from [tablexxx] order by id where title ''" 'where就是条件查询啦
rsTemp.open ,oConn ,1,1
if not rsTemp.eof then
while not rsTemp.eof

response.write("输出数据啦"&rsTemp("id"))
rsTemp.movenext

wend

end if

name=Request.QueryString("name")
age=Request.QueryString("age")
addr=Request.QueryString("addr")

应该是

name=Request.form("name")
age=Request.form("age")
addr=Request.form("addr")

首先你得清楚你这段代码只有一个语句 如果你全部代码就是这些的话 肯定是查询不出来结果的 大家只是根据你提供的这段代码找出问题. 实际上你这段代码还没写完.所以点了查询出不了结果很正常

上面2位兄弟的答案合二为一是正确的答案。

name=Request.QueryString("name")
age=Request.QueryString("age")
addr=Request.QueryString("addr")

应该是

name=Request.form("name")
age=Request.form("age")
addr=Request.form("addr")

Sql= Sql & "and name like ’%"& name &"%’"
Sql= Sql & "and age = ’"& age &"’"
Sql= Sql & "and addr like ’%"& addr &"%’"
sql语句少了空格 ,应该是
Sql= Sql & " and name like ’%"& name &"%’"
Sql= Sql & " and age = ’"& age &"’"
Sql= Sql & " and addr like ’%"& addr &"%’"

Sql= Sql & "and name like ’%"& name &"%’"
Sql= Sql & "and age = ’"& age &"’"
Sql= Sql & "and addr like ’%"& addr &"%’"
sql语句少了空格 ,应该是
Sql= Sql & " and name like ’%"& name &"%’"
Sql= Sql & " and age = ’"& age &"’"
Sql= Sql & " and addr like ’%"& addr &"%’"


许昌县17614899269: asp多条件查询的sql语句
望哗心安: 循环: set rs1 set rs2 sql1 = "select * from t_main where show = true order by id desc" do while not rs1.eof rs1("id")sql2 = "select * from u_user where id = " & rs1("id") & " and show = true order by id desc"rs2("id") rs1.movenext loop

许昌县17614899269: ASP多条件查询怎么做? -
望哗心安: 跟单一的搜索条件也是一致的,只是出现多个条件,使用or 来连接各自的条件就可以做到多条件查询

许昌县17614899269: asp 多条件查询 -
望哗心安: 首先我只能无语的.很多个点.然后sql="select * from inf where 1=1 " if lx<>"" then sql=sql + " and lx=...

许昌县17614899269: asp.net中,多条件查询的sql语句怎么写?! -
望哗心安: String sqlText="select * from table where 学号列=... and 班级列=... and 系别列=...";

许昌县17614899269: ASP中条件查询sql数据 -
望哗心安: 1.去掉所有单引号,因为“分数”字段是整数类型(我推断如此,否则不能用大于小于号)2.第二个小于等于号方向错,改为 "and 分数一般sql带比较符的表达式,字段名一定写在左边,这样效率较高!

许昌县17614899269: asp 多条件查询代码或者按关键字查询 -
望哗心安: 1、要查询的数据库名称:data.mdb 数据库中表为:data 数据库表data的字段有:title、about 由于无数据添加页面,所以在数据库各字段中应添加数据,方便查询演示.2、数据库打开文件conn.asp:<% Server.scriptTimeout="10" connstr="...

许昌县17614899269: asp多条件查询 -
望哗心安: sql="select * from 数据库表 where id>0" if trim("贷款类型")"" then sql=sql&" and 表字段="&贷款类型取值&" " end if if trim("针对用户")"" then sql=sql&" and 表字段end if if trim("贷款用途")"" then sql=sql&" and 表字段>"&贷款用途取值&" " end if if trim("贷款期限")"" then sql=sql&" and 表字段>"&贷款期限取值&" " end if

许昌县17614899269: 关于SQL数据库多条件数据查询和asp分页显示 -
望哗心安: 查询可以用if else 去做. 例如: sql="select * from ........." `````````````` xh=request("型号") ······ if xh<>"" then sql=sql+" and 型号='"&xh&"'" 分页可以用 <%TurnPage(rs,20,"型号="&xh&"&其他6个参数·······...

许昌县17614899269: asp查询调用SQL数据库代码 -
望哗心安: 记得在最上面加上这句指令集using System.Data.SqlClient; 在后台代码中加入:String constr = "server=.\\sqlexpress;database=test;uid=sa;pwd=123";这一种是sa用户连接的代码 //String constr = "server=.\\sqlexpress;database=...

许昌县17614899269: asp脚本 sql 语句如何多表单查询 -
望哗心安: 楼主的是不是要多表关联查询啊!如果是代码如下:<!--#include file="conn.asp"--> '连接数据库<% dim rs,sql sql="select distinct a.名称,a.内容,b.类型,c.信息 from a,b,c where a.名称=c.名称 and b.信息=c.信息"'查询语句如上 set rs=conn.execute(sql)%><%'显示代码略%>

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网