我是一名初學者,現在學習VB數據庫,請問在查詢的時候,我想批號=text1.text 
料號=text2.text,這樣的語句如何寫,請各位高手幫忙

解决方案 »

  1.   

    "select ... from ... where 批號 = '" & text1.text & "' and 料號 = '" & text2.text & "'"
      

  2.   

    '字段是数字型
    sqlstring="select * from table1 where 批號=" & text1.text & " and 料號=" & text2.text'字段是字符型
    sqlstring="select * from table1 where 批號='" & text1.text & "' and 料號='" & text2.text & "'"
      

  3.   

    "select ... from ... where 批號  = " & Text1.Text & " and 料號 = " & text2.Text
      

  4.   

    我的建议是:
    "select ... from ... where 批號  = " & trim(Text1) & " and 料號 = " & trim(text2)
    这样比较不容易出错
      

  5.   


    if trim(text1) <> "" and trim(text2) <> "" then
    ...
    elseif trim(text1) <> "" then
    ...
    elseif trim(text2) <> "" then
    ...
    end if
      

  6.   

    dim strWhere as string
    strWhere=""
    if trim(text1)<>"" then strWhere = strWhere & "批號=" & text1
    if trim(text2)<>"" then strWhere = strWhere & " and 料號=" & text2
    strSQL="Select * from mytable where " & strWhere
    set Rst=conn.execute(strSQL)
      

  7.   

    这样较完全
    strWhere=""
    if trim(text1)<>"" then strWhere = strWhere & " where 批號=" & text1if trim(text2)<>"" then 
       if strWhere="" then
           strWhere = strWhere & " where 料號=" & text2
       else
           strWhere = strWhere & " and 料號=" & text2  
       end if
    end if
    strSQL="Select * from mytable " & strWhere
    set Rst=conn.execute(strSQL)
      

  8.   

    if isdate(first_Date) then "进货日期 >='" & first_Date & "'"
    if isdate(end_Date) then "进货日期 <='" & end_Date & "'"