机房收费系统之组合查询

如果提到组合查询大家映入眼帘的是什么,当我刚刚接触到她的时候感觉她很难,因为在做组合查询的时候好多同学都做出来了,做出来以后都说很难,她如“犹抱琵琶半遮面”的美女,让我对她充满了好奇,在师傅第一次验收之后当时我确实做出来了,感觉还洋洋得意,但是当师傅验收的时候,我才注意到一个问题就是我的组合查询并没有做到精确查询当检验到数字的时候,她根本就没有反应,比如卡号控制在0到100以内的时候我才发现我原来并没有把所有的数据进行限制,大于100的数字都出来了,但是我当时并没有注意到这个问题,后来我看了十期连江伟师兄的博客才认识到这个问题,于是对我的代码做到了一个修改,问题出现在我们写的SQL语句根本就不对,我们把数字当成了字符所以特没有办法查出来。

  If Combo7.Text = "" Then
    
    If IsNumeric(Text1.Text) Then
    
    txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "" & Text1.Text & ""
    Else
    txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'"
    End If
'    txtSQL = "select * from student_Info where " & Trim(FileName(Combo1.Text)) & "" & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'"
    
    
    Else
    If Combo8.Text = "" Then
    If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) Then
    txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "" & Text1.Text & "" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "" & Text2.Text & ""
    ElseIf IsNumeric(Text1.Text) And Not IsNumeric(Text2.Text) Then
    txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "" & Text1.Text & "" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'"
    ElseIf Not IsNumeric(Text1.Text) And IsNumeric(Text2.Text) Then
    txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "" & Text2.Text & ""
    Else
     txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'"
     End If
     
       Else
       If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) And IsNumeric(Text3.Text) Then
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "" & Text1.Text & "" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "" & Text2.Text & "" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "" & Text3.Text & ""
       ElseIf IsNumeric(Text1.Text) And IsNumeric(Text2.Text) And Not IsNumeric(Text3.Text) Then
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "" & Text1.Text & "" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "" & Text2.Text & "" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "'" & Trim(Text3.Text) & "'"
       ElseIf IsNumeric(Text1.Text) And Not IsNumeric(Text2.Text) And IsNumeric(Text3.Text) Then
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "" & Text1.Text & "" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "" & Text3.Text & ""
       ElseIf IsNumeric(Text1.Text) And Not IsNumeric(Text2.Text) And Not IsNumeric(Text3.Text) Then
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "" & Text1.Text & "" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "'" & Trim(Text3.Text) & "'"
       ElseIf Not IsNumeric(Text1.Text) And IsNumeric(Text2.Text) And IsNumeric(Text3.Text) Then
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "" & Text2.Text & "" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "" & Text3.Text & ""
       ElseIf Not IsNumeric(Text1.Text) And Not IsNumeric(Text2.Text) And IsNumeric(Text3.Text) Then
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "" & Text3.Text & ""
       ElseIf Not IsNumeric(Text1.Text) And IsNumeric(Text2.Text) And Not IsNumeric(Text3.Text) Then
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "" & Text2.Text & "" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "'" & Trim(Text3.Text) & "'"
       Else
       
       
       txtSQL = "select * from Line_Info where " & Trim(FileName(Combo1.Text)) & Trim(Combo4.Text) & "'" & Trim(Text1.Text) & "'" & Trim(FileName(Combo7.Text)) & " " & Trim(FileName(Combo2.Text)) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'" & Trim(FileName(Combo8.Text)) & " " & Trim(FileName(Combo3.Text)) & Trim(Combo6.Text) & "'" & Trim(Text3.Text) & "'"
       End If
       
    End If
 End If


你可能感兴趣的:(机房收费系统之组合查询)