Selecting values that are not on the listview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #1

    Selecting values that are not on the listview

    This is my sample code

    [CODE=vb]...
    rsSubjects.Open "Select * From LoadSectionSubj ects Where Courses.Title=' " & txtCourse.Text & "' And Sections.Title= '" & txtSection.Text & "' And " & "Semester=' " & txtSemester.Tex t & "' Order by SubjectCode ASC", dbConnection, 1, 1
    Dim i As Long
    While Not rsSubjects.EOF
    For i = 1 To lvwCourses.List Items.Count
    'The subject column is on the subitems 2 of the listview
    If rsSubjects!Subj ectCode<>lvwCou rses.ListItems. Item(i).SubItem s(2)
    cboSubjectCode. AddItem rsSubjects!Subj ectCode
    End If
    rsSubjects.Move Next
    Next i
    Wend
    ...[/CODE]
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    I think you have spend more that enough time here to know the guidelines .

    Why you have posted these codes here without mentioning anything ?

    Comment

    • lotus18
      Contributor
      • Nov 2007
      • 865

      #3
      Originally posted by debasisdas
      I think you have spend more that enough time here to know the guidelines .

      Why you have posted these codes here without mentioning anything ?
      OK. Sorry for that. Just like with the title, I just want to display the values (subjectcode) on the combobox that are not listed on the listview.

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        You Need to Keep a Flag to check if any Item Present..
        and then Add To The Combo Box..
        heck This :

        [CODE=vb]...
        rsSubjects.Open "Select * From LoadSectionSubj ects Where Courses.Title=' " & txtCourse.Text & "' And Sections.Title= '" & txtSection.Text & "' And " & "Semester=' " & txtSemester.Tex t & "' Order by SubjectCode ASC", dbConnection, 1, 1
        Dim i As Long
        Dim AddFlag As Boolean
        While Not rsSubjects.EOF
        AddFlag = True
        For i = 1 To lvwCourses.List Items.Count
        'The subject column is on the subitems 2 of the listview
        If rsSubjects!Subj ectCode=lvwCour ses.ListItems.I tem(i).SubItems (2)
        AddFlag = False
        Exit For
        End If
        Next i
        If AddFlag Then
        cboSubjectCode. AddItem rsSubjects!Subj ectCode
        End If
        rsSubjects.Move Next
        Wend
        ..[/CODE]


        Better option is : First Build a List of all the Subjects from ListView, and use a "Not In " SQL Query

        Regards
        Veena

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          Find the items in the listbox and pass the same to the SQL statment using NOT IN.

          Comment

          • lotus18
            Contributor
            • Nov 2007
            • 865

            #6
            I was thinking about 'NOT IN' in sql statement but I used '<>' operator for the comparison, BTW, thanks to both of you ^ _ ^

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              Originally posted by lotus18
              I was thinking about 'NOT IN' in sql statement but I used '<>' operator for the comparison, BTW, thanks to both of you ^ _ ^
              When comparing multiple values always use IN / NOT IN for better result.

              Comment

              • lotus18
                Contributor
                • Nov 2007
                • 865

                #8
                Originally posted by debasisdas
                When comparing multiple values always use IN / NOT IN for better result.
                Thanks for new info. I learned something new today. Thanks again.

                Comment

                Working...