sql = "select * from book where bname like '%" & txtbname.Text & "%' and bauthor like '%" & txtauthor.Text & "%' and bpublish like '%" & txtpublish.Text & "%' and bdescription like '%" & txtdescription.Text & "%' order by bookid desc"组合查询,有是四个组合条件,这样写是不是效率比较低,我该怎么优化一下呢?
谢谢。

解决方案 »

  1.   

    分析,在SQL中,用LIKE是比较费时间的,所以最好是少用。同时 ,四个TEXT框,输入条件是,一定会有没有输入的条件的时候,就会出现 LIKE "%"的情况,其实这种情况下就等于这个条件没有。所以,把生成SQL语句的代码多写些,
    Dim WhereStr as string
    if txtbname.Text<>"" then 
        WhereStr="bname like '%" & txtbname.Text & "%'"
    ELSE IF ....
        .....
    ENDIF
    这样是一个概率的问题,如果四个全输入的话,是一样的,但如果只输入一个的问,速度会比你的快些!
      

  2.   


    同意  flxa()  的方法.