Setting up a second combo box from DataSet

mikjall77

New member
Joined
Feb 24, 2008
Messages
2
Programming Experience
1-3
I am writing a school project in VB005 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 debug, it shows my iUserID value as 0. Any help on this is greatly appreciated.
Main code:
VB.NET:
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:
VB.NET:
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
 
Last edited:
Aww... I feel sorry for you, being put on .NET 2 and then being taught to do data access like that.. No wonder the computing industry makes slow progress when the freshest recruits are taught the old crap..
 
INcidentally, reading the DW2 link in my signature might be the biggest data access favour you ever do yourself.. For sure carry on writing that junk to satisfy your course requirements, but after the course is over, throw that knowledge away because it's wrong and hideous on so many levels.

Actually.. 10 years ago, I wasnt taught OO like you are being taught now.. it may be something to raise with the course director
 
Back
Top