"select ... from ... where 批號 = '" & text1.text & "' and 料號 = '" & text2.text & "'"
'字段是数字型 sqlstring="select * from table1 where 批號=" & text1.text & " and 料號=" & text2.text'字段是字符型 sqlstring="select * from table1 where 批號='" & text1.text & "' and 料號='" & text2.text & "'"
"select ... from ... where 批號 = " & Text1.Text & " and 料號 = " & text2.Text
我的建议是: "select ... from ... where 批號 = " & trim(Text1) & " and 料號 = " & trim(text2) 这样比较不容易出错
if trim(text1) <> "" and trim(text2) <> "" then ... elseif trim(text1) <> "" then ... elseif trim(text2) <> "" then ... end if
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)
这样较完全 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)
if isdate(first_Date) then "进货日期 >='" & first_Date & "'" if isdate(end_Date) then "进货日期 <='" & end_Date & "'"
sqlstring="select * from table1 where 批號=" & text1.text & " and 料號=" & text2.text'字段是字符型
sqlstring="select * from table1 where 批號='" & text1.text & "' and 料號='" & text2.text & "'"
"select ... from ... where 批號 = " & trim(Text1) & " and 料號 = " & trim(text2)
这样比较不容易出错
if trim(text1) <> "" and trim(text2) <> "" then
...
elseif trim(text1) <> "" then
...
elseif trim(text2) <> "" then
...
end if
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)
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)
if isdate(end_Date) then "进货日期 <='" & end_Date & "'"