我开发系统的时候,需要写一个多条件的查询语名,提示错误码是"falseandtrue"
请各位高手帮我指点一下.我想跟据   >"Txt开始时间" 而  <"Txt结束时间"  查询Dim Cnn As ADODB.Connection
Dim Rs As ADODB.Recordset
Private Sub Cmd查询_Click()
    Dim Str As String
    Dim Temp As String
    Dim temp1 As String
    Dim temp2 As String
Set Cnn = New ADODB.Connection
Cnn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=金光油脂;Data Source=pakbai"Cnn.Open
Cnn.CursorLocation = adUseClient
Set Rs = New ADODB.Recordset
  If Trim(Txt油罐编号.Text) <> "" Then
        Temp = "tkid=" & "'" & Trim(Txt油罐编号.Text) & "'"
        If Str <> "" Then
             Str = Str + " and " + Temp
        Else
             Str = Temp
        End If
    End If    If Trim(Txt开始时间.Text) <> "" And Trim(Txt结束时间.Text) <> "" Then
        temp1 = "timestart>=" & "'" & Trim(Txt开始时间.Text) & "'"
        temp2 = "timestart<=" & "'" & Trim(Txt结束时间.Text) & "'"
        Temp = (Temp > temp1) & "And" & (Temp < temp2)
       
        If Str <> "" Then
            Str = Str + " and " + Temp
        Else
            Str = Temp
        End If
    End If
    
   
  Str = "select * from Tankstore where " & Str
Rs.Open Str, Cnn, adOpenDynamic, adLockOptimistic
Set DG.DataSource = Rs
 End Sub

解决方案 »

  1.   

    Temp = (Temp > temp1) & "And" & (Temp < temp2)
    当然是不对了
      

  2.   

    Temp = (Temp > temp1) & "And" & (Temp < temp2)
    请问这句代码要怎么写,很急的
      

  3.   

    Temp = (Temp > temp1) & "And" & (Temp < temp2)
    这句话要达到的目的?
    怀疑应该是
    Temp = "(" & Temp & ">" & temp1 & ")" & "And" & "(" & Temp & "<" & temp2 & ")"
    不过看你前面temp已经是个"tkid=" & "'" & Trim(Txt油罐编号.Text) & "'"了
    不能再在后面跟上">"了,所以我看不太懂