Dim sql As String
Dim str As String
Dim conn As New Connection
Dim rst As New ADODB.Recordset
Dim tmpno As String
Dim tmpchar As StringWith quotationno
  
    tmpno = .Getno
  
End Withtmpchar = Left(tmpno, 9)sql = "select * from quotation where refno like "
str = "DRIVER={SQL Server};SERVER=leon;UID=sa;PWD=800728;DATABASE=material"sql = "select * from quotation where refno like "要like tmpchar
怎么写,我写了好几个是错的

解决方案 »

  1.   

    //Dim conn As New ConnectionDim conn As New ADODB.Connection
      

  2.   

    //sql = "select * from quotation where refno like "要like tmpcharsql = "select * from quotation where refno like " & tmpchar
      

  3.   

    不是前面的每问题,就是sql那儿like后面怎么写
      

  4.   

    sql = "select * from quotation where refno like " & tmpchar
    这样可以。
      

  5.   

    还是出现
    实时错误'-2147217900 (8004e14)'
    [microsoft][odbc sql server driver][sql server]列名
    'Q20041019'无效。
      

  6.   

    Q20041019 是 tmpchar = Left(tmpno, 9)函数的产物
      

  7.   

    //sql = "select * from quotation where refno like " & tmpcharsql=" select * from quotation where refno like " & "'" & tmpchar & "'"这么试试!
      

  8.   

    也不是阿
    sql = "select * from quotation"
    就没问题
      

  9.   

    sql = " select * from quotation where refno like " & "'" & tmpchar & "'"
    str = "DRIVER={SQL Server};SERVER=leon;UID=sa;PWD=800728;DATABASE=material"
    conn.Open str
    rst.Open sql, connIf rst.EOF = True Then
        txtquotationno = tmpchar & "001"
    Else
        txtquotationno = "111"
    End Ifrst.Close
    conn.Close运行出来的结果不对吧
    我数据库quotation中的refno有Q20041019002这个数据,但是没有找到
      

  10.   

    & "'" & tmpchar & "%'"
      

  11.   

    在SQL里的语句如果是:
    select * from quotation where id like '%fdsa%'  '内容需要用单引号引上
    在VB里就要写成
    str= "select * from quotation where id like" & "'%" & str1 & "%'"  '需要把这个单引号和%用双引号引起来.   str1是一个变量你要查询的内容是什么啊??你后面想like 什么啊??
    比如id like 1
    就要等于1 
    tmpchar =1
    语句执行没问题,那就说明语句没错,结果不是你想要的,那说明你的tmpchar的值没有设置好!!
    你在加上%按这个帖子上面的语句试试!
      

  12.   

    对了对了,但有一点不明,为什么不添%号就不行,我用的不是like吗
      

  13.   

    like也需要用%来进行模糊查询!!用%代替你不知道的字符!
      

  14.   

    难道这样改不对吗?
    & "'" & tmpchar & "%'"