Results 1 to 2 of 2

Thread: [2005] Setting up a second combo box from DataSet

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    11

    [2005] Setting up a second combo box from DataSet

    I am writing a school project and am trying to hook up a second combo box that gets its information of what to display from the first combo box. My application is where a student takes a "test" but they can choose what instructor they want in the first combo box. From there, they choose from a test of what each instructor offers in the second combo box. As of right now, my first combo box works great and my second combo box has nothing in it. Just a note, when I set up a watch while debugging, it shows my iUserID value as 0. Any help on this is greatly appreciated.
    Main code:
    Code:
    dsInstructor = oInstructor.GetData(m_UserID)
            dsUser = oUser.GetData
            cmgrInstructor = CType(Me.BindingContext(dsInstructor.Tables(0)), CurrencyManager)
            For x = 0 To dsUser.Tables(0).Rows.Count
                If dsUser.Tables(0).Rows(x).Item(0) = iStudentID Then
                    txtWelcome.Text = dsUser.Tables(0).Rows(x).Item("FullName")
                    Exit For
                End If
            Next
            cboInstructor.DataSource = dsInstructor.Tables(0)
            cboInstructor.DisplayMember = "FullName"
            cboInstructor.ValueMember = "UserID"
    
            dsTest = oTest.GetData(m_Test)
            
            cmgrTest = CType(Me.BindingContext(dsTest.Tables(0)), CurrencyManager)
            cboTest.DataSource = dsTest.Tables(0)
            cboTest.DisplayMember = "TestName"
            cboTest.ValueMember = "TestID"
    Class Code:
    Code:
    Private Function CreateDASelectCommand() As OleDb.OleDbCommand
            Dim sSQL As String      'string with SQL
            Dim cmd As New OleDb.OleDbCommand(sSQL, m_oCn) 'command object
            '---------------------------------------------------------
            '--- Set up the SELECT Command
            '---------------------------------------------------------
            sSQL = "select * from tblTest"   'SQL to use
            'sSQL &= " where UserID = " & sUserID
            cmd.CommandText = sSQL
            cmd.CommandType = CommandType.Text  'this is SQL rather than a stored procedure
            Return cmd 'return the full command
        End Function
    
    Public Function GetData(ByVal iUserID As Integer) As DataSet
            Dim sSQLOrig As String = ""   'The original SQL used for all records
            Try
                ''--- Create a new DataSet
                sSQLOrig = m_oDA.SelectCommand.CommandText
                m_oDA.SelectCommand.CommandText &= " where UserID = " & iUserID.ToString
                'm_oDA.SelectCommand.CommandText &= " and TestID = " & sTestID.ToString
                m_oCn.Open()
                m_oDS = New DataSet
                ''--- Fill the DataSet with the Customers
                m_oDA.Fill(m_oDS, m_sClassName)
                m_oCn.Close()
                ''//--- Return the DataSet
                Return m_oDS
            Catch ex As Exception
                Throw ex
            Finally
                'reset SQL back to generic 'Grab Everything'
                m_oDA.SelectCommand.CommandText = sSQLOrig
            End Try
    
        End Function

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    11

    Re: [2005] Setting up a second combo box from DataSet

    Nevermind, I got it to work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width