求教!那位能告诉小弟vb中SQL的语法,主要是怎么在select中使用各种类型的变量和怎么在Data.RecordSource 中调用。以及怎么在data.DatabaseName 中引用数据库的相对路径,就是将整个文件夹(程序加数据库)移动后也不影响使用。还有这个vb提示数据类型不匹配
Data3.RecordSource = "select 客房号 from room where 客房类型 like '*" & roomtype & "*'" & "and 客人数<'*" & temp_num & "*'"
我想应该是--&"and 客人数<'*" & temp_num & "*'"--的错误。去掉它就没错了。客人数,temp_num 都是long  客房号,客房类型,roomtype  是string
请高手多多指教。谢谢了

解决方案 »

  1.   

    相对路径:
    app.path & 路径改正SQL:
    星号(*)用百分号(%)代替。
      

  2.   

    是string用* 别的类型用%吗?
      

  3.   

    还有 app.path & 路径 中的路径是本地机器上的绝对路径吗?
      

  4.   

    RecordSource 属性不支持变量,只支持常量
      

  5.   

    Data3.RecordSource = "select 客房号 from room where 客房类型 like '%" & roomtype & "%'" & "and 客人数 <" & temp_num 
      

  6.   

    //是string用* 别的类型用%吗?like是与%号匹配的还有 app.path是本地机器上的绝对路径
      

  7.   

    App.Path是你工程的路径,是绝对路径
      

  8.   

    to :LGYAN(紫衣随想)  like 也可以与*匹配  % 与* 好像都行?  我这里% 不行,不知怎搞地。大家看看下面的代码结果不对错哪里了Data3.RecordSource = "select 客房号 from room where 客房类型 like '*" & roomtype & "*'and 客人数<" & temp_num & "or 客人性别 like '*" & csex & "*' or 客人性别 like '空'"提示是:参数不足,期待是。
      

  9.   

    SELECT [客房号]
    FROM room
    WHERE 客房类型 Like '*" & roomtype & "*' And 
    客人数<" & temp_num & " Or (客人性别 Like '*" & csex & "*' 
    Or 客人性别 Like '空')SQL这样写是没错的啊,我在机器上也执行了,没有象你说的“参数不足,期待是。”之类提示啊
      

  10.   

    to fog(温柔的风):  SQL 当然没问题,但在Data3.RecordSource 中就不对了。
      

  11.   

    to fog(温柔的风):  你的代码是不会出现错误提示了(直接加在属性里)但结果不对。客房类型的选择没做。 但我不知道错那里。晕!
      

  12.   

    SQL中用强制转换函数
    好象是CAST
      

  13.   


    改进代码:没有错误提示了。但还有问题Data3.RecordSource = "select 客房号 from room where 客人性别 like '*" & csex & "*' or 客人性别 like '空' and 客人数<" & temp_num & " and 客房类型 like '*" & roomtype & "*'"
    现在的问题是总有一个约束条件不执行。 这个不执行的是  客人数< temp_num
      

  14.   


    Data3.RecordSource="select 客房号 from room where 客人性别 like exist ('*"&csex&"*','空') and 
    and 客人数<" & temp_num & " and 客房类型 like '*" & roomtype & "*'"
      

  15.   

    Data3.RecordSource = "select 客房号 from room where (客人性别 like '*" & csex & "*' or 客人性别 like '空') and 客人数<" & temp_num & " and 客房类型 like '*" & roomtype & "*'"