日期:2014-05-16  浏览次数:20808 次

关于ACCESS的LIKE查询问题,郁闷啊!大家进来帮帮忙
Dim   SqlDatabaseName,SqlPassword,SqlUsername,SqlLocalName
scadb= "database/a.mdb "     'dbdns   为各文件中设置的路径,请不要改动
connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source= "   &   Server.MapPath( " "&scadb& " ")

If   IsObject(conn)   =   false   Then

'On   Error   Resume   Next
set   conn   =   Server.CreateObject( "ADODB.Connection ")
conn.Open   ConnStr
If   Err.Number   <>   0   Then
      Response.write   err.Description  
      Response.write   "系统日常维护中! "
      Response.End()
end   if

end   if

Dim   rs,sqltext,WhereSql
dim   keyword,type,sculpt
dim   typeid
dim   action
keyword=Request.Form( "keyword ")
type=Request.Form( "type ")
typeid=request( "typeid ")
sqltext   =   "Select   id,title   From   new   where   category= '新闻 ' "


if   keyword <> " "   then
WhereSql=WhereSql+ "   and   title   like   '* "&keyword& "* ' "
end   if

if   type <> " "   then
'WhereSql=WhereSql+ "   and   type= ' "&type& " ' "
end   if


sqltext=sqltext+WhereSql
'Response.Write   sqltext
 
Set   rs=Server.Createobject( "Adodb.RecordSet ")

rs.Open   sqltext,conn,1,1
                                    Response.Write   rs.BOF   & "=== "&   rs.EOF  

用SQL放到ACCESS里面的查询框里明明可以查询到数据,但是RS.EOF、RS.BOF都是返回TRUE,如果把LIKE的查询去掉就能查询出来,怎么回事呀?好郁闷!

------解决方案--------------------


--在ADO的sql串中通配符用%:
select * from 表名 where 字段名 like '%abc% '

--在纯Access中通配符用*:
select * from 表名 where 字段名 like '*abc* '



------解决方案--------------------
呵呵,分不够啊!


if keyword <> " " then
WhereSql=WhereSql+ " and title like '* "&keyword& "* ' "

-->


if keyword <> " " then
WhereSql=WhereSql+ " and title like '% "&keyword& "% ' "
------解决方案--------------------
WhereSql=WhereSql+ " and title like '* "&keyword& "* ' "
中,把“*”号改为 “%”就可以了。
在like语句中,“*”只能用一次!