Problem when comparing array and values from table

Author Message
blasted777

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 8/20/2009
  • Status: offline
Problem when comparing array and values from table Thursday, August 20, 2009 3:08 AM (permalink)
0
Hi guys,
 
Please advise on the following problem:
 
I have two tables in MS Access database and I want two compare each value to get matches. But I only recieve first match intstead of couple of them.
 
Here is the code:
 
 <TD><Select multiple Name="lawyers_involved">
 <option></option>
    <%
   lawyers_involved = rs("Lawyers_involved")
   lawyers_involved = split(lawyers_involved, ",")
   rs1.movefirst
   For i=0 to UBound(lawyers_involved)
   
   Do Until rs1.EOF
    lawyerstr = rs1("DisplayName") 
            
   If rs1("displayname") = lawyers_involved(i) Then  
  %>
   <option><%=rs1("displayname")%></option>
  <%
    
   
  %> 
         
  <%
    
    End If
    rs1.movenext
    
    Loop 
   Next
     
       
  %>
 
#1
    ehvbs

    • Total Posts : 3320
    • Scores: 110
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    Re:Problem when comparing array and values from table Thursday, August 20, 2009 5:19 AM (permalink)
    0
    For i=0 to UBound(lawyers_involved)
       rs1.MoveFirst
       Do Until rs1.EOF
            lawyerstr = rs1("DisplayName") 
            If rs1("displayname") = lawyers_involved(i) Then  
               <option><%=rs1("displayname")%></option>
            End If
            rs1.movenext
       Loop 
    Next
     
    #2
      blasted777

      • Total Posts : 2
      • Scores: 0
      • Reward points : 0
      • Joined: 8/20/2009
      • Status: offline
      Re:Problem when comparing array and values from table Thursday, August 20, 2009 8:44 PM (permalink)
      0
      I've done it like this but now I recieve no matches at all. 
      <%
         
         lawyers_involved = rs("Lawyers_involved")
         lawyers_involved = split(lawyers_involved, ",")
         For i=1 to UBound(lawyers_involved) 
              rs1.movefirst 
               Do Until rs1.EOF 
              lawyerstr = rs1("DisplayName")     
              If rs1("displayname") = lawyers_involved(i) Then  
        %>
              <option><%=rs1("displayname")%></option>
        <%
          End If
          rs1.movenext
                  Loop 
         Next
        %>
      <message edited by blasted777 on Thursday, August 20, 2009 8:47 PM>
       
      #3
        ehvbs

        • Total Posts : 3320
        • Scores: 110
        • Reward points : 0
        • Joined: 6/22/2005
        • Location: Germany
        • Status: offline
        Re:Problem when comparing array and values from table Sunday, August 23, 2009 5:43 AM (permalink)
        0
        Adapt code like this:

          Const adClipString =          2 ' 00000002
           Const adOpenKeyset =          1 ' 00000001
           Const adOpenStatic =          3 ' 00000003
         
           Dim oFS   : Set oFS   = CreateObject( "Scripting.FileSystemObject" )
           Dim sMdb  : sMdb      = oFS.GetAbsolutePathName( ".\slrs.mdb" )
           Dim oCNCT : Set oCNCT = CreateObject( "ADODB.Connection" )
           Dim sCS   : sCS       = Join( Array( _
                "Provider=Microsoft.Jet.OLEDB.4.0" _
              , "Data Source=" & sMdb _
           ), ";" )
           Dim sSQL  : sSQL      = Join( Array( _
                "SELECT A.Lawyer"            _
              , "FROM   [lawyersa] AS A" _
              , "     , [lawyersb] AS B" _
              , "WHERE A.Lawyer = B.Lawyer"  _
           ), " " )
         
           oCNCT.Open sCS
         
           WScript.Echo "----- A"
           WScript.Echo oCNCT.Execute( "SELECT * FROM [lawyersa]" ).GetString( adClipString, , " ", vbCrLf, "<NULL>" )
           WScript.Echo "----- B"
           WScript.Echo oCNCT.Execute( "SELECT * FROM [lawyersb]" ).GetString( adClipString, , " ", vbCrLf, "<NULL>" )
           WScript.Echo "----- In both (sql)"
           WScript.Echo oCNCT.Execute( sSQL ).GetString( adClipString, , " ", vbCrLf, "<NULL>" )
         
           WScript.Echo "----- In both (pedestrian)"
           Dim aB  : aB      = oCNCT.Execute( "SELECT * FROM [lawyersb]" ).GetRows()
         
           Dim oRS
         If False Then
           Set oRS = CreateObject( "ADODB.Recordset" )
           oRS.Open "SELECT * FROM [lawyersa]", oCNCT, adOpenStatic
         Else
           Set oRS = oCNCT.Execute( "SELECT * FROM [lawyersa]" )
         End If
         
           Dim nRow
           For nRow = 0 to UBound( aB, 2 )
               WScript.Echo "check B", aB( 0, nRow )
               oRS.MoveFirst
               Do Until oRS.EOF
                  WScript.Echo "check A", oRS.Fields( "Lawyer" ).Value
                  If oRS.Fields( "Lawyer" ).Value = aB( 0, nRow ) Then
                     WScript.Echo "**** in both", oRS.Fields( "Lawyer" ).Value
                  End If
                  oRS.MoveNext
               Loop
           Next
         
           oCNCT.Close


        output:

        === getLawyers: demo join =================
         ----- A
         Ann
         Bill
         Emma
         
         ----- B
         Ann
         Cecil
         Emma
         
         ----- In both (sql)
         Ann
         Emma
         
         ----- In both (pedestrian)
         check B Ann
         check A Ann
         **** in both Ann
         check A Bill
         check A Emma
         check B Cecil
         check A Ann
         check A Bill
         check A Emma
         check B Emma
         check A Ann
         check A Bill
         check A Emma
         **** in both Emma
         === getLawyers: 0 done (00:00:00) =========


        to

          (a) see how to solve your task with sql and avoid all the
                problems of pedestrian loops

          (b) see that the pedestrian way (especially the .MoveFirst)
               works in principle (as I told you)

          (c) check whether your code failed to .MoveFirst (Cursor type?)
               or didn't loop as expected (how did you get the array?)

         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9