编程环境是win2000,vb6,access2000
有这四个vb中的变量:bhText , xmText ,dh1Text ,dh2Text
代码如下:
if trim(bhText)="" then bhText="%"
if trim(xmText)="" then xmText="%"
if trim(dh1Text)="" then dh1Text="%"
if trim(dh2Text)="" then dh2Text="%"adodc1.recordsource="select * from clientinfo where clientid like '" & bhText & "' and clientname like '" & xmText & "' and phone like '" & dh1Text & "' and phone2 like '" & dh2Text & "'"但是,如果clientinfo中的某字段,比如phone2有一些记录是空串的,查询结果就会出错,搞了几天也搞不明白为什么,也想不到更好的办法
请各位高手帮帮忙吧,100分相送
有这四个vb中的变量:bhText , xmText ,dh1Text ,dh2Text
代码如下:
if trim(bhText)="" then bhText="%"
if trim(xmText)="" then xmText="%"
if trim(dh1Text)="" then dh1Text="%"
if trim(dh2Text)="" then dh2Text="%"adodc1.recordsource="select * from clientinfo where clientid like '" & bhText & "' and clientname like '" & xmText & "' and phone like '" & dh1Text & "' and phone2 like '" & dh2Text & "'"但是,如果clientinfo中的某字段,比如phone2有一些记录是空串的,查询结果就会出错,搞了几天也搞不明白为什么,也想不到更好的办法
请各位高手帮帮忙吧,100分相送
Access中的通配符用“*”号,虽然你的问题与此无关。
if trim(bhText)="" then bhText="*"
if trim(xmText)="" then xmText="*"
if trim(dh1Text)="" then dh1Text="*"
if trim(dh2Text)="" then dh2Text="*"
如果字段中有空串的,也要选出来:
adodc1.recordsource="select * from clientinfo where (clientid is null or clientid like '" & bhText & "') and (clientname is null or clientname like '" & xmText & "') and (phone is null or phone like '" & dh1Text & "') and (phone2 is null or phone2 like '" & dh2Text & "')"
cn.execute "update clientinfo set phone2 = 'N/A' where isnull(phone2,'')=''"因为多加任何值都有可能会有冲突,所以建议在查询时多加过滤条件就行了~
If Trim(bhtext) <> "" Then sql = sql & " and clientid like '" & bhtext & "*'"
If Trim(xmText) <> "" Then sql = sql & " and clientname like '" & Replace(xmText, "'", "''") & "*'"
If Trim(dh1Text) <> "" Then sql = sql & " and phone like '" & dh1Text & "*'"
If Trim(dh2Text) <> "" Then sql = sql & " and phone2 like '" & dh2Text & "*'"
adodc1.RecordSource = sql